This works (changed just two things, the way of taking input, as already pointed out above, and added a break in switch case)
Code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package circle;
import java.util.Scanner;
/**
*
* @author window user
*/
public class Circle {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
double pie = 3.14159;
String input;
char letter;
Scanner key = new Scanner(System.in);
System.out.println("Enter the radius of the circle: ");
double radius = Double.parseDouble(key.nextLine());
System.out.println("Enter C to calculate circumference or enter A to calculate area of the circle: ");
input = key.nextLine();
letter = input.charAt(0);
switch (letter){
case 'a':
case 'A':
double area = radius*radius*pie;
System.out.println("Area of the circle is: " + area);
break;
case 'c':
case 'C':
double circumference = 2*radius*pie;
System.out.println("Circumference of the circle is " + circumference);
break;
default:
System.out.println("Enter c to calculate circumference or enter A to calculate are of the circle");
}
}
}
Sample runs-
Code
me@kali:~$ java circle.Circle
Enter the radius of the circle:
10
Enter C to calculate circumference or enter A to calculate area of the circle:
C
Circumference of the circle is 62.8318
me@kali:~$ java circle.Circle
Enter the radius of the circle:
10
Enter C to calculate circumference or enter A to calculate area of the circle:
A
Area of the circle is: 314.159
me@kali:~$ java circle.Circle
Enter the radius of the circle:
10.001
Enter C to calculate circumference or enter A to calculate area of the circle:
A
Area of the circle is: 314.22183494159