In this program, we will read base, altitude from the user and calculate the area of the Parallelogram. Then we will print the result.
Program/Source Code:
The source code to calculate the area of the Parallelogram is given below. The given program is compiled and executed successfully.
// Java program to calculate the
// area of Parallelogram
import java.util.Scanner;
public class Main {
static float calcuateAreaOfParallelogram(float base, float altitude) {
float result = 0.0F;
result = base * altitude;
return result;
}
public static void main(String[] args) {
Scanner SC = new Scanner(System.in);
float base = 0;
float altitude = 0;
float area = 0;
System.out.printf("Enter the value of base: ");
base = SC.nextFloat();
System.out.printf("Enter the value of altitude: ");
altitude = SC.nextFloat();
area = calcuateAreaOfParallelogram(base, altitude);
System.out.printf("Area of Parallelogram is: %f\n", area);
}
}
Output:
Enter the value of base: 1.2
Enter the value of altitude: 3.5
Area of Parallelogram is: 4.200000
Explanation:
In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contain two static methods calcuateAreaOfParallelogram() and main().
The calcuateAreaOfParallelogram() method is used to calculate the area of Parallelogram based on given base and altitude.
The main() method is an entry point for the program. Here, we read base, altitude from the user using Scanner class. Then we calculated the area of Parallelogram using the calcuateAreaOfParallelogram() method and printed the result.
In this program, we will read base, altitude from the user and calculate the area of the Parallelogram. Then we will print the result.
Program/Source Code:
The source code to calculate the area of the Parallelogram is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we imported the "java.util.Scanner" package to read input from the user. And, created a public class Main. It contain two static methods calcuateAreaOfParallelogram() and main().
The calcuateAreaOfParallelogram() method is used to calculate the area of Parallelogram based on given base and altitude.
The main() method is an entry point for the program. Here, we read base, altitude from the user using Scanner class. Then we calculated the area of Parallelogram using the calcuateAreaOfParallelogram() method and printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer