Assignemnt #72 Again with the Number-Guessing
Code
/// Name: Jake Johnson
/// Period: 7
/// Program Name: NumberGuessingAgain
/// File Name: NumberGuessingAgain.java
/// Date Finished: 1/11/2015
import java.util.Scanner;
import java.util.Random;
public class NumberGuessingAgain
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int secret, guess;
int tries = 1;
System.out.println("I have chosen a number between 1 and 10. Try to guess it.");
System.out.print("Your guess: ");
guess = keyboard.nextInt();
secret = 1 + r.nextInt(10);
do
{
System.out.println("\nNope, guess again.");
System.out.print("Your guess: ");
guess = keyboard.nextInt();
tries++;
}
while (guess != secret);
System.out.println("\nYep, it was " + secret + ".");
System.out.println("Yep it only took " + tries + " tries.");
}
}
Picture of the output