Assignment #72
Code
///jack newsom
///period 5
///program NumGuess3
///filename NumGuess3.java
///date completed 10/13/15
import java.util.Scanner;
import java.util.Random;
public class NumGuess3
{
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.println("Your guess: ");
int guess = bot.nextInt();
int t=0;
t++;
int actual = r.nextInt(10) + 1;
do
{
System.out.println("That is incorrect. Guess again.");
System.out.print("Your guess: ");
guess = bot.nextInt();
t++;
} while ( guess != actual);
System.out.println("That's right! You're a good guesser.");
System.out.println("It only took you " + t + " tries.");
}
}
Picture of the output