Write the program to calculate the area of rectangle in JAVA:
Answers
import java.util.scanner;
class AreaOfRectangle
{
public static void main(String args[ ])
{
Scanner s= new Scanner (System.in);
System.out.println(" ENTER THE LENGTH:");
double l=s.nextDouble();
System.out.println(" ENTER THE BREADTH:");
double b=s.nextDouble();
double area=l*b;
System.out.println("AREA OF RECTANGLE IS:"+area);
}
}
output
ENTER THE LENGTH :
5
ENTER THE BREADTH :
4
AREA OF RECTANGLE IS :
10.0
Java program for the above question is as follows:
Explanation:
import java.util.Scanner;//Package
public class Area//class definition
{
public static void main(String[] args)//main function definition.
{
Scanner s= new Scanner (System.in);//object.
System.out.println("Enter the length and breadth to find the area");//print the message for the user.
double l=s.nextDouble();//take the value for length.
double b=s.nextDouble();//take the value for breadth.
System.out.println("The area of a rectangle is: "+l*b);//print the area.
}
}
Output ;
- If the user input as 10 and 4, then the output is 40.
Code Explanation :
- The above code is in java which is used to calculate the area of a rectangle.
- The above code will take the value for length and breadth and then calculate the area by the help of formula.
Learn More :
- JAVA : https://brainly.in/question/13792074