Java program to find perimeter of rectangle

In this post we are going to learn java program to find perimeter of rectangle.

Java program to find perimeter of rectangle

java program to find perimeter of rectangle

First input length and width of rectangle from user. Next apply perimeter formula, perimeter = 2 * (length + width). Lastly print the perimeter value.

Also read – rectangle java program

Here’s the java program to find perimeter of rectangle,

import java.util.Scanner;

public class PerimeterOfRectangleDemo
{    
   public static void main(String []args)
   {
      int length, width, perimeter;
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter length of rectangle : ");
      length = sc.nextFloat();
      System.out.print("Enter width of rectangle : ");
      width  = sc.nextFloat();
      perimeter = 2 * (length + width);
      System.out.println("Perimeter of rectangle : " + perimeter);
      sc.close();
   }          
}

Output:

Enter length of rectangle : 2
Enter width of rectangle : 5
Perimeter of rectangle : 14