Created
June 7, 2016 22:33
-
-
Save eginter/bd61b06830d4656e8efe52b25920da49 to your computer and use it in GitHub Desktop.
Guess a number game
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class KeepGuessing { | |
public static void main( String[] args ) { | |
Scanner keyboard = new Scanner(System.in); | |
int secret, guess; | |
secret = 1 + (int)(Math.random()*10); | |
System.out.println( "I have chosen a number between 1 and 10." ); | |
System.out.println( "Try to guess it." ); | |
System.out.print( "Your guess: "); | |
guess = keyboard.nextInt(); | |
while ( secret != guess ) { | |
System.out.println( "That is incorrect. Guess again." ); | |
System.out.print( "Your guess: "); | |
guess = keyboard.nextInt(); | |
} | |
System.out.println( "That's right! You're a good guesser."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment