I. Requirements: When the program is running
1. Prompt the user to enter a number
2. If you guessed, the output guessed right.
3. If you do not guess the number is large or small, and prompts to continue guessing until the Guess
4. User press Enter 0 to exit the game
5. Write with a while loop
6. The guessed numbers are randomly generated between 1 and 100
Two. Code
import java.util.scannerclass guessing{ public static void Main () { scanner sc = new scanner (System.in) ; int num = (int) (Math.random () *100+1); system.out.println ("Please enter") int guess = sc.nextint (); while (Guess!=num ) { if (guess==0) { system.out.println ("Exit Game"); break; } if (guess>num) { system.out.println ("Big Up"); } if (Guess<num) { system.out.println ("small"); } if (Guess==num) { sytem.out.println ("guessed right"); break; } system.out.println ("Please enter") &nBsp; gusee = sc.nextint (); } }}
In fact, there are many ways to write, I only wrote one of them, if there are mistakes or suggestions want to put forward, I hope you can send a message or messages thank you.
Java guessing numbers game