Write a program in java to input the length and breadth of a rectangle and calculate its area and perimeter
Answers
Answered by
1
Explanation:
import java.util.Scanner;
public class Area_Perimeter
{
public static void main(String[] args)
{
int l, b, perimeter, area;
Scanner s = new Scanner(System.in);
System.out.print("Enter length of rectangle:");
l = s.nextInt();
System.out.print("Enter breadth of rectangle:");
b = s.nextInt();
perimeter = 2 * (l + b);
System.out.println("Perimeter of rectangle:"+perimeter);
area = l * b;
System.out.println("Area of rectangle:"+area);
}
}
Output:
$ javac Area_Perimeter .java
$ java Area_Perimeter
Enter length of rectangle:4
Enter breadth of rectangle:5
Perimeter of rectangle:18
Area of rectangle:20
Similar questions
English,
5 months ago
Social Sciences,
5 months ago
English,
11 months ago
History,
11 months ago
Computer Science,
1 year ago
Computer Science,
1 year ago