Pages

Labels

Write a Java program that accepts the radius of a circle and displays the options as follows : 1. find diameter of a cicle.(2* radius) 2. find area of circle.( Π* radius * radius) 3. find circumference of a circle.( 2 * Π* radius) 4. exit. Use case statement to implement each option and display the corresponding output.

import java.util.Scanner;
public class Circle
{
    public static void main(String [] args)
    {
        Scanner input = new Scanner(System.in);
        System.out.println("Enter Radius ");
        double r = input.nextDouble();
        System.out.println(r);
        System.out.printf("1.Diameter\n2.circumference\n3.area\n4.exit\n");
        System.out.println("Enter number you want ");
        int n = input.nextInt();
        switch(n)
        {
            case 1:
                {
                    System.out.println("The diameter of the circle is "+(r*2));
                    break;
                }
            case 2:
                {
                    System.out.println("The Circumference of the circle is "+2*Math.PI*r);
                    break;
                }
            case 3:
                {
                    System.out.println("The Area of the circle is "+Math.PI*r*r);
                    break;
                }
            case 4:
                {
                    return;
                }
            default:
                {
                    System.out.println("Wrong Input");
                }

        }
  }
}