Answers for "Write a Java program to print the area and perimeter of a rectangle"

1

Java program to find perimeter of a rectangle

import java.util.Scanner;
public class PerimeterOfRectangleDemo
{    
   public static void main(String []args)
   {
      float length, width, perimeter;
      Scanner sc = new Scanner(System.in);
      System.out.print("Please enter length of rectangle: ");
      length = sc.nextFloat();
      System.out.print("Please enter width of rectangle: ");
      width  = sc.nextFloat();
      perimeter = 2 * (length + width);
      System.out.println("Perimeter of rectangle: " + perimeter);
      sc.close();
   }          
}
Posted by: Guest on February-09-2021
0

perimeter of rectangle java program

import java.util.Scanner;

public class RectanglePerimeter {
    public static void main(String[] args) {
        new RectanglePerimeter().getValues();
    }

    //get user input from console
    public void getValues() {
        Scanner sc=new Scanner(System.in);

        double length= sc.nextDouble();

        double breadth=sc.nextDouble();
        RectanglePerimeter obj=new RectanglePerimeter();
       double result= obj.perimeterCalculator(length,breadth);
        System.out.println(result);

    }

    //write logic to find perimeter of rectangle here
    public double perimeterCalculator(double length, double breadth) {
        double perimeter=(2*length)+(2*breadth);
        return perimeter;



    }
}
Posted by: Guest on May-08-2021

Code answers related to "Write a Java program to print the area and perimeter of a rectangle"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language