perimeter of rectangle java program

Solutions on MaxInterview for perimeter of rectangle java program by the best coders in the world

showing results for - "perimeter of rectangle java program"
Juan José
09 Aug 2019
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}
Tyler
28 Jan 2020
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);
Todd
07 Mar 2017
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}