Assignment #65
Code
///jack newsom
///period 5
///prog NumGuessCounter
///filename NumGuessCounter.java
///date completed 10/7/15
import java.util.Scanner;
import java.util.Random;
public class NumGuessCounter
{
public static void main(String[] args)
{
Random r = new Random();
Scanner bot = new Scanner(System.in);
System.out.println("I HAVE CHOSEN A NUMBER BETWEEN 1 AND 10. TRY TO GUESS IT.");
System.out.print("YOUR GUESS: ");
int guess = bot.nextInt();
int actual = r.nextInt(9) + 1;
int tries = 0;
tries++;
while ( guess != actual )
{
System.out.println("THAT IS INCORRECT. TRY AGAIN.");
System.out.println("YOUR GUESS: ");
guess = bot.nextInt();
tries++;
}
System.out.println("That's right! You're a good guesser.");
System.out.println("It only took you " + tries + " tries.");
}
}
Picture of the output