import java.util.Scanner;
public class GuessingGame
{
public static void main (String [] args)
{
int PlayAgain =1;
while (PlayAgain==1){
int max = 10;
int min = 1;
int randomnum = 0;
randomnum = (int)(Math.random() * ((max - min) + 1)) + min;
//System.out.println ("Random: " + randomNum);
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number between 1 and 10");
int guess=sc.nextInt();
// System.out.println("Enter your name");
// String name=sc.next();
if (guess>10 || guess <1){
System.out.println("NOT A VALID NUMBER, PLEASE ENTER A NUMBER BETWEEN 1 AND 10");
guess=sc.nextInt();
} else {
System.out.println("You number was " + guess + " The correct number was: " + randomnum);
}
if (guess == randomnum){
System.out.println("Winner!, play again if you'd like by pressing 1, or 2 to end program.");
}else {
System.out.println("Incorrect, try again if you'd like by pressing 1, or 2 to end program.");
}
PlayAgain=sc.nextInt();
if (PlayAgain==2){
System.exit(0);
}}}}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.