A Program to Find the Area of a Parallelogram

In this example, we are giving a program to find the area of a parallelogram. The rule of finding the area of a parallelogram is: A = base * vertical_height.

Program to find the area of a parallelogram:

  1. import java.util.Scanner; //Scanner class helps to get input from user
  2. class triangle {
  3. public static void main(String[] args) {
  4. Scanner s = new Scanner(System.in); //Scanner class object declaration
  5. System.out.println("Enter the base of parallelogram: ");
  6. float b = s.nextFloat(); // takes float input base from keyboard or user or run time
  7. System.out.println("Enter the height of parallelogram: ");
  8. float h = s.nextFloat(); // takes float input height from keyboard or user or run time
  9. float area = b * h;
  10. System.out.println("Area of Parallelogram: "+ area);
  11. }
  12. }

Output:

Enter the base of parallelogram: 3
Enter the height of parallelogram: 4
Area of Parallelogram: 12.00