Assignemnt #61 Keep Guessing
Code
/// Name: Jake Johnson
/// Period: 7
/// Program Name: KeepGuessing
/// File Name: KeepGuessing.java
/// Date Finished: 12/7/2015
import java.util.Scanner;
import java.util.Random;
public class KeepGuessing
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int secret, guess;
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);
while (guess != secret)
{
System.out.println("Nope, guess again.");
System.out.print("Your guess: ");
guess = keyboard.nextInt();
}
System.out.println("Yep, it was " + secret + ".");
}
}
Picture of the output