WAP to accept length of a rectangular room.Breadth is 2/4th of the length.Calculate and display the area in Java.
Answers
Answered by
16
The given problem is solved using language - Java.
import java.util.Scanner;
public class Area{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
double l,b;
System.out.print("Enter length: ");
l=sc.nextDouble();
b=2/4.0*l;
System.out.println("Therefore, breadth is: "+b);
System.out.println("Area is: "+l*b);
}
}
- Line 1: Import scanner class for taking input.
- Line 2: Start of class.
- Line 3: Start of main() method.
- Line 4: Object of scanner class created.
- Line 5: Length and breadth variables are declared.
- Line 6-7: Length of the rectangle is taken as input.
- Line 8: Scanner class is closed.
- Line 9: Breadth is calculated using the relation given.
- Line 10: Breadth is displayed on the screen.
- Line 11: Area is displayed on the screen.
- Line 12: End of main()
- Line 13: End of class.
See attachment for output.
Attachments:
Similar questions
Math,
3 hours ago
Social Sciences,
3 hours ago
Environmental Sciences,
6 hours ago
Math,
8 months ago