Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class NumberGuessingGame {
- public static void main(String[] args) {
- int abfrage = 0;
- do {
- System.out.println("Hallo Du! Willkommen zu meinem kleinen Zahlenratespiel!");
- System.out.println(" ");
- System.out.print("Okay, wie viele Versuche möchtest du haben? Wähle zwischen 4 oder 8 Versuchen: ");
- int i = Konsole.readInt();
- System.out.println(" ");
- System.out.println("Okay du hast "+i+" Versuche.");
- System.out.println(" ");
- System.out.println("Errate die Zahl zwischen 1 und 100: ");
- int zufall = (int) (Math.random()*101);
- int zahl = Konsole.readInt();
- int runde = 1 ;
- if (zahl<zufall) {
- System.out.println("Die Zahl ist zu klein.");
- }
- if (zahl>zufall){
- System.out.println("Die Zahl ist zu groß.");
- }
- if (zahl==zufall) {
- System.out.println("Du hast die Zahl erraten!");
- }
- do { runde++;
- zahl = Konsole.readInt();
- if (zahl<zufall) {
- System.out.println("Die Zahl ist zu klein.");
- }
- if (zahl>zufall){
- System.out.println("Die Zahl ist zu groß.");
- }
- if (zahl==zufall) {
- System.out.println("Du hast die Zahl erraten!");
- }
- if (runde==i) {
- System.out.println(" ");
- System.out.println("Du hast keine Versuche mehr!");
- System.out.println(" ");
- System.out.print("Möchtest du nochmal spielen ? Tippe für ja die 0 und für nein die 1: ");
- abfrage = Konsole.readInt();
- if (abfrage==1) {
- return;
- }
- if (abfrage==0) {
- zahl=zufall;
- break;
- }
- }
- }while (zahl!=zufall) ;
- } while (abfrage==0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement