Assignment: Module 02 - Part 02
01. Write a program to calculate the perimeter and the area of the rectangle . Let length and breadth be declared as an integer variable whose values are predefined. The output should be displayed in a floating format.Assignment: Module 02 - Part 02
An Example :
Input:
length=4 breadth=2
Expected Output:
The area of the rectangle is : 8.0
The perimeter of the rectangle is :12.0
Here is a Java program that calculates the area and perimeter of a rectangle, given the length and breadth as input:
public class Rectangle {
public static void main(String[] args) {
int length = 4;
int breadth = 2;
float area = length * breadth;
float perimeter = 2 * (length + breadth);
System.out.println("The area of the rectangle is: " + area);
System.out.println("The perimeter of the rectangle is: " + perimeter);
}
}
Output:The area of the rectangle is: 8.0
The perimeter of the rectangle is: 12.0
Note that in this example, the values of the length and breadth are predefined and hard-coded into the program. If you want to take input from the user, you can use the Scanner class to read input from the keyboard.