Computer Science, asked by SuryanshRam, 6 hours ago

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 anindyaadhikari13
16

\textsf{\large{\underline{Solution}:}}

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);

   }

}

\textsf{\large{\underline{Explanation}:}}

  1. Line 1: Import scanner class for taking input.
  2. Line 2: Start of class.
  3. Line 3: Start of main() method.
  4. Line 4: Object of scanner class created.
  5. Line 5: Length and breadth variables are declared.
  6. Line 6-7: Length of the rectangle is taken as input.
  7. Line 8: Scanner class is closed.
  8. Line 9: Breadth is calculated using the relation given.
  9. Line 10: Breadth is displayed on the screen.
  10. Line 11: Area is displayed on the screen.
  11. Line 12: End of main()
  12. Line 13: End of class.

See attachment for output.

Attachments:
Similar questions