Assignemnt #61 and Keep Guessing
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name: KeepGuessing.java
/// File Name: Keep Guessing
/// Date Finished: 12/16/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 choice = 1 + r.nextInt(10);
System.out.println("Try to Guess my number between 1 and 10. ");
int entry = keyboard.nextInt();
System.out.println();
while ( entry != choice )
{
System.out.println("That is incorrect. Guess again.");
System.out.print("Your Guess: ");
entry = keyboard.nextInt();
}
if ( choice == entry )
{
System.out.println( "Correct! That's my number.");
}
}
}
Picture of the output