fork download
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class CircleStuff {
  5. public static void main(String[] args){
  6. Scanner myScanner = new Scanner(System.in);
  7. //Creates some variables
  8. double pi = 3.14159265359;
  9. double sum = 0;
  10. boolean done = false;
  11.  
  12. //while loop to keep asking for new input
  13. while (done == false){
  14.  
  15. //Asks for input about what you want to do and stores it.
  16. System.out.println("Do you want to know the circumference or area of the circle?");
  17. String answer = myScanner.nextLine();
  18. answer = answer.toLowerCase();
  19.  
  20. //Compares the answer to the input of the user and calculates the proper formula corresponding with the input
  21. if (answer.equals("circumference")){
  22. System.out.println("What is the radius of the circle?");
  23. double radius = myScanner.nextDouble();
  24. String test = myScanner.nextLine();
  25. sum = radius * pi;
  26. System.out.println("The circumference of the circle is: " + sum);
  27. }else if (answer.equals("area") ){
  28. System.out.println("What is the radius of the circle?");
  29. double radius = myScanner.nextDouble();
  30. String test = myScanner.nextLine();
  31. sum = radius * radius * pi;
  32. System.out.println("The area of the circle is: " + sum);
  33. }else{
  34. System.out.println("I didn't understand \"" + answer + "\", please try again." );
  35. }
  36.  
  37. //Asks the user if they want to do another calculation and stores the input
  38. System.out.println("Do you want to try again?");
  39. String answer2 = myScanner.nextLine();
  40. answer2 = answer2.toLowerCase();
  41.  
  42. //Compares the answer of the input and either continues the loop or breaks it.
  43. if (answer2.equals("yes")){
  44. done = false;
  45. }else if (answer2.equals("no")){
  46. done = true;
  47. }else{
  48. System.out.println("I didn't understand \"" + answer2 + "\", please try again." );
  49. answer2 = myScanner.nextLine();
  50. answer2 = answer2.toLowerCase();
  51. }
  52. }
  53. }
  54.  
  55. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: class CircleStuff is public, should be declared in a file named CircleStuff.java
					public class CircleStuff {
					       ^
1 error
stdout
Standard output is empty