Computer Science, asked by abhaypratapsingh8d, 1 month ago

Write a program to find the area of a triangle ( Hint : area=1/2 b*h)​

Answers

Answered by anindyaadhikari13
5

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎de is written in Java.

import java.util.*;

public class TriangleArea{

   public static void main(String x[]){

       double base,height,area;

       Scanner sc=new Scanner(System‎.‎in);

       System.out.print("Enter the base of the triangle: ");

       b‎ase=sc‎.‎nextDouble();

       System.out.print("Enter the height of the triangle: ");

       height=sc‎.‎nextDouble();

       sc‎.‎close();

       area=1/2.0 * base * height;

       System.out.print("The area of the triangle is: "+area+" sq units.");  

   }

}

\texttt{\textsf{\large{\underline{Logic}:}}}

  • Accept the b‎ase and height of the triangle as input.
  • Calculate area using formula.
  • Display the area.

See the attachment for output.

Attachments:
Similar questions