Computer Science, asked by amnaperween19, 5 hours ago

write a program in java to find the area of triangle Take height and base from user​

Answers

Answered by anindyaadhikari13
2

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

The given co‎‎de is written in Java.

import java.util.*;

public class TriangleArea{

   public static void main(){

       Scanner _=new Scanner(System.in);

       float height,base,area;

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

       height=_.nextFloat();

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

       base=_.nextFloat();

       _.close();

       area=base * height * 1/2.0f; // As A = bh/2

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

   }

}

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

  • Accept the height and base of the triangle.
  • Calculate area, area = 1/2 * height * base.
  • Display area.

See the attachment for output.

Attachments:
Answered by kamalrajatjoshi94
0

Answer:

Program:-

import java.util.*;

public class Main

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

int b,h;

double ar=0;

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

b=in.nextInt();

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

h=in.nextInt();

ar=1.0/2.0*b*h;

System.out.println("The area of triangle="+ar);

}

}

Attachments:
Similar questions