Assignemnt #65 and Number-Guessing with a Counter
Code
/// Name: Brian Phillips
/// Period: 5
/// Program name: KeepGuessingCounter.java
/// File Name: Number-Guessing with a Counter
/// Date Finished: 12/19/2015
import java.util.Scanner;
import java.util.Random;
public class KeepGuessingCounter
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice = 1 + r.nextInt(10);
int tries = 0;
System.out.println("Try to Guess my number between 1 and 10. ");
int entry = keyboard.nextInt();
tries++;
while ( entry != choice )
{
System.out.println("That is incorrect. Guess again.");
System.out.print("Your Guess: ");
entry = keyboard.nextInt();
tries++;
}
if (entry == choice)
{
System.out.println("That's right it only took you " + tries + " tries.");
}
}
}
Picture of the output