Advertisement
Guest User

Untitled

a guest
Sep 12th, 2017
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.99 KB | None | 0 0
  1. public class NumberGuessingGame {
  2.   public static void main(String[] args) {    
  3.     int abfrage = 0;
  4.     do {
  5.       System.out.println("Hallo Du! Willkommen zu meinem kleinen Zahlenratespiel!");
  6.       System.out.println("                            ");
  7.       System.out.print("Okay, wie viele Versuche möchtest du haben? Wähle zwischen 4 oder 8 Versuchen: ");
  8.       int i = Konsole.readInt();
  9.       System.out.println("                            ");
  10.       System.out.println("Okay du hast "+i+" Versuche.");
  11.       System.out.println("                            ");
  12.       System.out.println("Errate die Zahl zwischen 1 und 100: ");
  13.       int zufall = (int) (Math.random()*101);
  14.       int zahl = Konsole.readInt();
  15.       int runde = 1 ;
  16.      
  17.       if (zahl<zufall) {
  18.         System.out.println("Die Zahl ist zu klein.");  
  19.       }
  20.       if (zahl>zufall){
  21.         System.out.println("Die Zahl ist zu groß.");
  22.       }
  23.       if (zahl==zufall) {
  24.         System.out.println("Du hast die Zahl erraten!");  
  25.       }
  26.      
  27.       do {        runde++;
  28.         zahl = Konsole.readInt();
  29.         if (zahl<zufall) {
  30.           System.out.println("Die Zahl ist zu klein.");  
  31.         }
  32.         if (zahl>zufall){
  33.           System.out.println("Die Zahl ist zu groß.");
  34.         }
  35.         if (zahl==zufall) {
  36.           System.out.println("Du hast die Zahl erraten!");  
  37.         }
  38.        
  39.         if (runde==i) {
  40.           System.out.println("                            ");
  41.           System.out.println("Du hast keine Versuche mehr!");  
  42.           System.out.println("                            ");
  43.           System.out.print("Möchtest du nochmal spielen ? Tippe für ja die 0 und für nein die 1: ");
  44.           abfrage = Konsole.readInt();
  45.           if (abfrage==1) {
  46.             return;
  47.           }
  48.           if (abfrage==0) {
  49.             zahl=zufall;
  50.             break;
  51.           }
  52.         }  
  53.        
  54.       }while (zahl!=zufall) ;
  55.      
  56.     } while (abfrage==0);
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement