1 Packagecom.xt.homework.hw09;2 ImportJava.util.Scanner;3 /**4 * 4. Guess the number game. Randomly generates an integer of 1-100,5 * Let the user guess, guess big (or guess small) have a hint;6 * Until the user guesses the right, the prompt succeeds, the program ends. 7 * 8 * @authorTin Yiu Phase two9 * Yang BulongTen */ One Public classHomeWork04 { A Public Static voidMain (string[] args) { - Doubleb =math.random (); -b*=100; the if((int) (b+0.5) > (int) b) { -B= (int) b+1;} - Else{ -B= (int) b;} + while(1==1){ -System.out.println ("Please enter the number you guessed:"); +Scanner scan =NewScanner (system.in); A intA =scan.nextint (); at if(a>b) { -SYSTEM.OUT.PRINTLN ("---you guessed---");} - if(a<b) { -SYSTEM.OUT.PRINTLN ("---you guessed---");} - if(a==b) { -System.out.println ("+ + Congratulations, guessed right + +"); in Break;} - } to}
Boring learning, playing games is also very good!
"Java" is an interesting number game.