This is a Java Program to Create a Simple Class to Find out the Area and Perimeter of Rectangle.

Formula:

Perimeter of rectangle = 2 * (length + breadth)

Area of rectangle = length * breadth

Formula:

Perimeter of rectangle = 2 * (length + breadth)

Area of rectangle = length * breadth

Enter the length and breadth of the rectangle as input. Now we use the given formula to calculate the area and perimeter of rectangle.

Here is the source code of the Java Program to Create a Simple Class to Find out the Area and Perimeter of Rectangle. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

import java.util.Scanner;

public class Area_Perimeter

`{`

public static void main(String[] args)

`{`

int l, b, perimeter, area;

Scanner s = new Scanner(System.in);

System.out.print("Enter length of rectangle:");

l = s.nextInt();

System.out.print("Enter breadth of rectangle:");

b = s.nextInt();

perimeter = 2 * (l + b);

System.out.println("Perimeter of rectangle:"+perimeter);

area = l * b;

System.out.println("Area of rectangle:"+area);

`}`

`}`

advertisements

Output:

$ javac Area_Perimeter .java $ java Area_Perimeter Enter length of rectangle:4 Enter breadth of rectangle:5 Perimeter of rectangle:18 Area of rectangle:20

**Sanfoundry Global Education & Learning Series – 1000 Java Programs.**

Here’s the list of Best Reference Books in Java Programming, Data Structures and Algorithms.