Assignment #72 and Again with the number guessing
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Again with the number guessing
///File Name: NumberGuessing4.java
///Date Finished: 10/26/15
import java.util.Scanner;
import java.util.Random;
public class NumberGuessing4
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
System.out.println( "I'm thinking of a number between 1-10." );
int num, guess, n;
n= 0;
num = 1 + r.nextInt(10);
do
{
System.out.print( "Your Guess: " );
guess = keyboard.nextInt();
n++;
if ( num == guess )
System.out.println( "That's Right! You're a good guesser.\nIt only took you " + n + " tries." );
else
System.out.println( "That is incorrect. Guess again." );
} while ( num != guess );
}
}
Picture of the output