Assignment #72 AgainWiththeNumberGuessing
Code
/// Name: Lacey Reese
/// Period: 5
/// Program Name: AgainWiththeNumberGuessing
/// File Name: AgainWiththeNumberGuessing.java
/// Date Finished 1/8/2016
import java.util.Scanner;
import java.util.Random;
public class AgainWiththeNumberGuessing
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess, number, tries;
number = 1 + r.nextInt(10);
System.out.println( "Get ready to play the best number guessing game. Pick a number between 1-10!" );
tries = 0;
do
{
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
tries++;
if ( guess != number )
{
System.out.println( "That is incorrect. Guess again." );
}
} while ( guess != number );
System.out.println( "That's right! Good work!" );
System.out.println( "It took you " + tries + " tries." );
}
}
Picture of the output
//