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. Random random = new Random();
  13. System.out.println("유령게임");
  14. boolean feeling_brave = true;
  15. int score = 0;
  16. int ghost_door;
  17. int door_num;
  18. while(feeling_brave==true){
  19. ghost_door = random.nextInt(2)+ 1;
  20. System.out.println("문이 3개가 있다");
  21. System.out.println("3개의 문중 1개의 문 뒤에 유령이 있다");
  22. System.out.print("몇 번 문을 열 것인가?\n");
  23. System.out.print("1,2 아니면 3?\n");
  24. Scanner scanner = new Scanner(System.in);
  25. door_num = scanner.nextInt();
  26. if(door_num == ghost_door){
  27. System.out.println("유령이다!");
  28. feeling_brave=false;
  29. }
  30. else{
  31. System.out.println("유령이 없다!");
  32. System.out.println("옆방으로 들어가라");
  33. score = score+1;
  34. }
  35. }
  36. System.out.println("도망쳐!");
  37. System.out.println("score :"+score);
  38. }
  39. }
Runtime error #stdin #stdout #stderr 0.06s 4386816KB
stdin
Standard input is empty
stdout
유령게임
문이 3개가 있다
3개의 문중 1개의 문 뒤에 유령이 있다
몇 번 문을 열 것인가?
1,2 아니면 3?
stderr
Exception in thread "main" java.util.NoSuchElementException
	at java.util.Scanner.throwFor(Scanner.java:862)
	at java.util.Scanner.next(Scanner.java:1485)
	at java.util.Scanner.nextInt(Scanner.java:2117)
	at java.util.Scanner.nextInt(Scanner.java:2076)
	at Ideone.main(Main.java:25)