Calculate area of a rectangle in Java
Input - Question 12
In this question, we will see how to input length and breadth of a rectangle in Java programming using the java input and find its area. To know more about java input click on the java input lesson.
Q12) Write a program in Java to input length and breadth of a rectangle and find its area.
Formula: area = length * breadth
Program
import java.util.Scanner;
public class Q12
{
public static void main(String args[])
{
int l,b,a;
Scanner sc=new Scanner(System.in);
System.out.print("Enter length of a rectangle ");
l=sc.nextInt();
System.out.print("Enter breadth of a rectangle ");
b=sc.nextInt();
a=l*b;
System.out.print("Area=" + a);
}
}
Output
Enter length of a rectangle 10 Enter breadth of a rectangle 5 Area=50