Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Q4
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- System.out.println("Circle?");
- System.out.println("Square?");
- System.out.println("Rectangle?");
- System.out.println("Exit?");
- String x = in.nextLine();
- if (x.equals ("Circle"))
- {
- System.out.print("What is the radius: ");
- double radius = in.nextDouble();
- System.out.println("Area is: " + Math.PI * Math.pow(radius, 2));
- }
- else
- if (x.equals ("Square"))
- {
- System.out.print ("What is the length: ");
- double length = in.nextDouble();
- System.out.println ("Area is: " + length * length);
- }
- else
- if (x.equals ("Rectangle"))
- {
- System.out.print ("What is the length: ");
- double length2 = in.nextDouble();
- System.out.print ("What is the width: ");
- double width = in.nextDouble();
- System.out.println ("Area is: " + length2 * width);
- }
- else
- if (x.equals ("Exit"))
- {
- System.out.println("Exit.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement