Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class adhoc3
- {
- public static void main(String[] args)
- {
- guessgame(9);
- }
- public static void guessgame(int max)
- {
- double random = Math.random() * 100;
- random = (int) random;
- System.out.println(random);Scanner scanner = new Scanner(System.in);
- int numact = 1;
- while (scanner.hasNext())
- {
- if (!scanner.hasNextInt())
- {
- if(scanner.hasNext("X"))
- {
- break;
- }
- else
- {
- max--;
- System.out.println("ungültige Eingabe");
- scanner.next();
- }
- }
- if (max == 0)
- {
- System.out.println("Verloren");
- return;
- }
- if (scanner.hasNextInt() && max > 0)
- {
- numact = scanner.nextInt();
- if (numact == -1)
- {
- System.out.println("Sie haben das Spiel beendet");
- return;
- } else if (numact > 99 || numact < 0)
- {
- max--;
- System.out.println("ungülltige Eingabe");
- } else if (numact == random)
- {
- max--;
- System.out.println("Gewonnen! Die gesuchte Zahl war" + random);
- System.out.println("Sie hätten noch " + max + " Versuche gehabt");
- } else if (numact < random)
- {
- max--;
- System.out.println(" Die gesuchte Zahl ist größer!");
- } else if (numact > random)
- {
- max--;
- System.out.println("Die gesuchte Zahl ist kleiner!");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement