Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class adhoc3
  3. {
  4. public static void main(String[] args)
  5. {
  6. guessgame(9);
  7. }
  8.  
  9. public static void guessgame(int max)
  10. {
  11. double random = Math.random() * 100;
  12. random = (int) random;
  13. System.out.println(random);Scanner scanner = new Scanner(System.in);
  14. int numact = 1;
  15.  
  16. while (scanner.hasNext())
  17. {
  18. if (!scanner.hasNextInt())
  19. {
  20. if(scanner.hasNext("X"))
  21. {
  22. break;
  23. }
  24. else
  25. {
  26. max--;
  27. System.out.println("ungültige Eingabe");
  28. scanner.next();
  29. }
  30. }
  31.  
  32. if (max == 0)
  33. {
  34. System.out.println("Verloren");
  35. return;
  36. }
  37. if (scanner.hasNextInt() && max > 0)
  38. {
  39. numact = scanner.nextInt();
  40. if (numact == -1)
  41. {
  42. System.out.println("Sie haben das Spiel beendet");
  43. return;
  44. } else if (numact > 99 || numact < 0)
  45. {
  46. max--;
  47. System.out.println("ungülltige Eingabe");
  48. } else if (numact == random)
  49. {
  50. max--;
  51. System.out.println("Gewonnen! Die gesuchte Zahl war" + random);
  52. System.out.println("Sie hätten noch " + max + " Versuche gehabt");
  53. } else if (numact < random)
  54. {
  55. max--;
  56. System.out.println(" Die gesuchte Zahl ist größer!");
  57. } else if (numact > random)
  58. {
  59. max--;
  60. System.out.println("Die gesuchte Zahl ist kleiner!");
  61. }
  62. }
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement