| 1. |
Write a menu driven program to print area of rectangle, perimeter of rectangle, and diagonal of rectangle |
|
Answer» Answer: import java.util.*; public class Rectangle { public static VOID main(String args[ ]) { Scanner in=new Scanner(System.in); int ch,l,b; System.out.println("Enter length:"); l=in.nextInt(); System.out.println("Enter breath:"); b=in.nextInt(); System.out.println("Enter 1 to calculate the area of rectangle"); System.out.println("Enter 2 to calculate the perimeter of rectangle"); System.out.println("Enter 3 to calculate the DIAGONAL of rectangle"); System.out.println("Enter the operation you WANT to perform"); ch=in.nextInt(); switch(ch) { case 1: int ar=0; ar=l*b; System.out.println("The area of rectangle="+ar); break; case 2: int PR=0; pr=2*(l+b); System.out.println("The perimeter of rectangle="+pr); break; case 3: double d=0.0; d=Math.sqrt(l*l+b*b); System.out.println("The diagonal of the rectangle="+d); break; default: System.out.println("Invalid choice"); } } |
|