Java Program to Calculate Area and Perimeter of Rectangle

Hello coders, in this post, we will learn Java program to calculate area and perimeter of Rectangle. In the previous tutorial, you have learned Java Program to calculate Area and Perimeter of Right Triangle

Let’s see the mathematical formula to find the area and perimeter of the rectangle.

Area of rectangle = length * breadth

Perimeter of rectangle = 2(length+ breadth)

Now let’s start to write the program. So the complete source code is given below.

Java Program to Calculate Area and Perimeter of Rectangle

What we Did?

  • First of all we have imported the util package.
  • Then created a class and named it Rectangle.
  • After that started main() method of the program.
  • Then inside main() method declared variables.
  • Then created object of the Scanner class.
  • Now asked the user to enter the length and breadth of the rectangle. Then read the value of length and breadth entered by the user.
  • Then calculated area of the rectangle using the formula area = length * breadth
  • In the next line calculated perimeter of the rectangle using the formula perimeter = 2 (length + breadth)
  • Then finally displayed the value of the area and perimeter of the rectangle on the screen.

Output

So guys, in this tutorial, we have learned Java Program to calculate Area and Perimeter of Rectangle. In the next tutorial, you will learn Java Program to calculate Area and Perimeter of Square.


Related Tutorials…

Leave a Comment