java

Java Program to Calculate Area of Rectangle

In this tutorial, we are going to see how to calculate the area of a rectangle in Java. In the following example, the user would provide the height and width values of the rectangle during program execution and the area would be calculated based on the values provided.
 

Java Program to Calculate Area of Rectangle:
import java.util.Scanner;

class Main {
   public static void main (String[] args)
   {
	   Scanner sc = new Scanner(System.in);
	   System.out.print("Enter the height of the rectangle: ");
	   double height = sc.nextDouble();
	   
	   System.out.print("Enter the width of the rectangle: ");
	   double width = sc.nextDouble();

	   double surface = height * width;
	   
	   System.out.println("The area of the rectangle is : "+surface);
   }
}

Output:

Enter the height of the rectangle: 2
Enter the width of the rectangle: 3
The area of the rectangle is : 6.0
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *