Write Java program to Find Area of Triangle


This is a Java program that calculates the area of a triangle given its base width and height.

  • The program first declares three double variables: base, height, and area.
  • It then prompts the user to enter the base width and height of the triangle using the nextDouble() method of the Scanner class.
  • To calculate the area of the triangle, the program multiplies the base width and height together, divides the result by 2, and stores the final result in the area variable.
  • Finally, the program outputs the calculated area to the console using the println() method, preceded by a string indicating that the value being printed is the area of the triangle.

Source Code

import java.util.*;
public class Area_Triangle
{
	public static void main(String []args)
	{
		double base,height,area;
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Base Width : ");
		base = input.nextDouble();
		System.out.print("Enter the Height : ");
		height = input.nextDouble();
 
		area = (base*height)/2;// Area of Triangle
		System.out.println("Area of Triangle: " + area);    
	}
}

Output

Enter the Base Width : 25.12
Enter the Height : 56.51
Area of Triangle: 709.7656