fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. getQuestion();
  13. }
  14.  
  15. public static String getQuestion () {
  16. Scanner input = new Scanner (System.in);
  17. System.out.print ("Ask any question you need answered and prepare yourself for the sage advice of......your computer.\nJust type \"exit\" when you can't handle the truth any longer.\nQuestion: ");
  18. String question = input.nextLine();
  19. String exit = "exit";
  20. while (!question.equals(exit)) {
  21. showAnswer();
  22. System.out.print("Question: ");
  23. question = input.nextLine();
  24. }
  25. return question;
  26. }
  27.  
  28. public static void showAnswer () {
  29. int answer = (int)(Math.random() * 10);
  30. switch (answer) {
  31. case 0: System.out.println ("1"); break;
  32. case 1: System.out.println ("2"); break;
  33. case 2: System.out.println ("3"); break;
  34. case 3: System.out.println ("4"); break;
  35. case 4:System.out.println ("5"); break;
  36. case 5:System.out.println ("6"); break;
  37. case 6:System.out.println ("7"); break;
  38. case 7: System.out.println ("8"); break;
  39. case 8: System.out.println ("9"); break;
  40. case 9: System.out.println ("10"); break;
  41. }
  42. return;
  43. }
  44. }
Success #stdin #stdout 0.15s 321280KB
stdin
1
2
3
exit
stdout
Ask any question you need answered and prepare yourself for the sage advice of......your computer.
Just type "exit" when you can't handle the truth any longer.
Question: 3
Question: 2
Question: 5
Question: