20. JAVA Program to find Area of the triangle using Base and Height values.
How does this program work?
- In this program you are going to learn about how to find out the Area of triangle using Java.
- In this program to take user inputs base and height values for the given Triangle.
- After that by using area of triangle formula we can get the Output.
Here is the code
// Area of Triangle
import java.util.Scanner;public class Triangle
{
public static void main(String args[])
{
double b,h,area;
System.out.println("Enter width and Height of triangle\n");
Scanner obj1=new Scanner(System.in );
b=obj1.nextDouble();
h=obj1.nextDouble();
//Area = (width*height)/2
area=(b*h)/2;System.out.println("Area of the triangle is:"+area );
}
}