Computer Science, asked by Anonymous, 11 months ago

Write a program in java to input the length and breadth of a rectangle and calculate its area and perimeter ​

Answers

Answered by aashiiiiiisinha
0

/**

* Java program to find perimeter and area of a rectangle.

*/

import java.util.Scanner;

public class Rectangle {

public static void main(String[] args) {

float length, width, area, perimeter;

// Create scanner class object

Scanner in = new Scanner(System.in);

// Input length and width of rectangle

System.out.print("Enter length of rectangle: ");

length = in.nextFloat();

System.out.print("Enter width of rectangle: ");

width = in.nextFloat();

// Calculate perimeter of rectangle

perimeter = 2 * (length + width);

// Calculate area of rectangle

area = length * width;

// Print perimeter and area of rectangle

System.out.println("Perimeter of rectangle is " + perimeter + " units.");

System.out.println("Area of rectangle is " + area + " sq. units.");

}

}

Similar questions