Write a program to enter length and breadth of a rectangle and calculate its Area(Ixb) and perimeter (2(1+b)). (4M)
Answers
Java Program :-
import java.util.*;
public class Rectangle
{
public static void main(String args[ ] )
{
Scanner sc = new Scanner(System.in);
double a = 0.0, p = 0.0;
double l = 0.0, b = 0.0;
System.out.println("Enter the length");
l = sc.nextDouble();
System.out.println("Enter the breadth");
b = sc.nextDouble();
a = l * b;
p = 2*(l + b);
System.out.println("Area =" +a);
System.out.println("Perimeter =" +p);
}
}
Variable description :-
V. name V. type. Description
l double to store the value of
length of rectangle.
b double to store the value of
breadth of rectangle.
a double to store and calculate
the value of area.
p double to store and calculate
the value of perimeter.