-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerimeterofRectangle.java
More file actions
24 lines (18 loc) · 964 Bytes
/
PerimeterofRectangle.java
File metadata and controls
24 lines (18 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Importing the Scanner class to take user input
import java.util.Scanner;
class PerimeterofRectangle {
public static void main(String[] args) {
// Creating a Scanner object to read input from the user
Scanner sc = new Scanner(System.in);
// Prompting the user to enter the length of the rectangle
System.out.print("Enter the length of the rectangle: ");
double length = sc.nextDouble(); // Reading length input
// Prompting the user to enter the width of the rectangle
System.out.print("Enter the width of the rectangle: ");
double width = sc.nextDouble(); // Reading width input
// Calculating the perimeter of the rectangle using the formula: 2 × (length + width)
double perimeter = 2 * (length + width);
// Displaying the calculated perimeter
System.out.printf("The perimeter of the rectangle is: ", perimeter);
}
}