Free Data Structures and Algorithms Course









Subscribe below and get all best seller courses for free !!!










OR



Subscribe to all free courses

How to calculate Area of Triangle through a Java program ?.

Program to calculate Area of Triangle in Java



import java.util.Scanner;

public class Triangle {

   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);

      double base = 0;
      double height = 0;
      double area = 0;

      System.out.print("Enter the length of base of triangle : "); 
      base = input.nextDouble();

      System.out.print("Enter the length of height of triangle : "); 
      height = input.nextDouble();

      area = (base * height) / 2;
    
      System.out.println("");
      System.out.println("The Area of Triangle is : "
                  + area);

   }

}


Output of the program : 


 
© 2021 Learn Java by Examples Template by Hubberspot