Assignment #72 and Again with the Number-Guessing
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Again with the Number-Guessing
/// File Name: NumberGuess.java
/// Date Finished: 10/19/2015
import java.util.Scanner;
import java.util.Random;
public class NumberGuess
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int tries= 0;
int number = 1 + r.nextInt(10);
int guess;
System.out.println( "I have chosen a number between 1 and 10. Try to guess it." );
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! You're a good guesser." );
System.out.println( "It only took you " + tries + " tries." );
}
}
Picture of the output