Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views4 pages

Guessing Game: Prompt User To Input Their Guess

The document describes a guessing game program that: 1. Prompts the user to input a guess for a randomly generated number between 0-9. 2. If the input is correct, the player proceeds to the next level to guess another number. If incorrect, the score is shown. 3. The program then asks if the user wants to play again - if yes, the game restarts, if no, the program exits.

Uploaded by

Reymart Nachor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views4 pages

Guessing Game: Prompt User To Input Their Guess

The document describes a guessing game program that: 1. Prompts the user to input a guess for a randomly generated number between 0-9. 2. If the input is correct, the player proceeds to the next level to guess another number. If incorrect, the score is shown. 3. The program then asks if the user wants to play again - if yes, the game restarts, if no, the program exits.

Uploaded by

Reymart Nachor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

GUESSING GAME

Prompt user to input their guess.

If input is correct player proceeds to next level and guess the next number:
If user entered wrong number, system shows scores and asks the user if he want to play again:
If no, program exits.

CODES:

/*members:
* Nachor,John Reymart P.
* Senorin,Nica E.
* Dizon, Claire B.
* De Grano, Katlyn I.
* Lumbres, Majie E.
*
*
*
*/
import java.util.Scanner;
public class Finals {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int deter=1, ans;
int mystnum;
int level = 1;
System.out.println("GUESS THE MYSTERY NUMBER:");
do{
mystnum=(int)(Math.random()*10);
System.out.println("Level "+level+"(Choose between 0 - 9)");
System.out.println("(FOR TESTING PURPOSES: Mystery number = "
+mystnum+")");
System.out.println("Input guess:");
ans = in.nextInt();
if(ans==mystnum)
level++;
else
deter=0;
}while(deter != 0);
System.out.println("Score: "+level);
Finals.quit();
in.close();
}
public static void quit(){
Scanner in = new Scanner(System.in);
System.out.println("Do you want to play again? Y/N");
String q = in.nextLine();
switch(q){
case "Y":
case "y":
Finals.main(null);
break;
case "N":
case "n":
System.out.println("Bye, quitter!");
System.exit(0);
break;
default:
Finals.quit();
break;
}
in.close();

}
}

You might also like