Assignemnt #72 and Again with the Number-Guessing
Code
import java.util.Random;
import java.util.Scanner;
public class AgainNumberGuessing
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(10);
int guess, tries = 0;
System.out.println("I'm thinking of a number between 1-10. Try to guess it. ");
System.out.println();
do
{
System.out.print("Your guess: ");
guess = keyboard.nextInt();
if ( guess != secretNumber )
{
System.out.println( "That is incorrect. Guess again. " );
}
tries++;
}
while ( guess != secretNumber );
System.out.println("That's right, You're a good guesser.");
System.out.println("It only took you " + tries + " tries. " );
}
}
Picture of the output