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.

0

Assignment: Module 02 - Part 02

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
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.

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.
👉Java Fundamentals Module 02 - Part 01👈

Post a Comment

0Comments
Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
✨ Updates