1import java.util.Scanner;
2public class PerimeterOfRectangleDemo
3{
4 public static void main(String []args)
5 {
6 float length, width, perimeter;
7 Scanner sc = new Scanner(System.in);
8 System.out.print("Please enter length of rectangle: ");
9 length = sc.nextFloat();
10 System.out.print("Please enter width of rectangle: ");
11 width = sc.nextFloat();
12 perimeter = 2 * (length + width);
13 System.out.println("Perimeter of rectangle: " + perimeter);
14 sc.close();
15 }
16}
1Scanner sc = new Scanner(System.in);
2System.out.println("Enter Width of the rectangle: ");
3double width = sc.nextDouble();
4System.out.println("Enter Height of the rectangle: ");
5double height = sc.nextDouble();
6sc.close();
7// Logic for finding the perimeter of the rectangle
8double perimeter = 2 * (width + height);
9System.out.println("Perimeter of Rectangle: " + perimeter);
1import java.util.Scanner;
2
3public class RectanglePerimeter {
4 public static void main(String[] args) {
5 new RectanglePerimeter().getValues();
6 }
7
8 //get user input from console
9 public void getValues() {
10 Scanner sc=new Scanner(System.in);
11
12 double length= sc.nextDouble();
13
14 double breadth=sc.nextDouble();
15 RectanglePerimeter obj=new RectanglePerimeter();
16 double result= obj.perimeterCalculator(length,breadth);
17 System.out.println(result);
18
19 }
20
21 //write logic to find perimeter of rectangle here
22 public double perimeterCalculator(double length, double breadth) {
23 double perimeter=(2*length)+(2*breadth);
24 return perimeter;
25
26
27
28 }
29}