/*Calculate area of Triangle in Java*/
//programming789.blogspot.com/
import java.util.Scanner;
class AreaTriangle {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the width of the Triangle:");
double base = scanner.nextDouble();
System.out.println("Enter the height of the Triangle:");
double height = scanner.nextDouble();
double area = (base* height)/2;
System.out.println("Area of Triangle is: " + area);
}
}
//programming789.blogspot.com/
import java.util.Scanner;
class AreaTriangle {
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the width of the Triangle:");
double base = scanner.nextDouble();
System.out.println("Enter the height of the Triangle:");
double height = scanner.nextDouble();
double area = (base* height)/2;
System.out.println("Area of Triangle is: " + area);
}
}
● Save the file as AreaTriangle.java.
● When the program is run, the following output is displayed:
Output:
Enter the width of the Triangle:
12
Enter the height of the Triangle:
14
Area of Triangle is: 84.0
12
Enter the height of the Triangle:
14
Area of Triangle is: 84.0