Assignemnt #65 and Number Guessing Game with a Counter
Code
///Name: Ben Borglin
///Period: 6
///Program name: Number Guessing Game with a counter
///file name: CountNumber.java
///Date Finsihed: 10/21/15
import java.util.Scanner;
import java.util.Random;
public class CountNumber
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice, x;
x = 1 + r.nextInt(10);
int tries = 0;
System.out.println("Im thinking of a number between 1 to 10.");
System.out.print("Your Guess: ");
choice = keyboard.nextInt();
while ( choice != x )
{
System.out.println("Sorry that was incorrect ... Try again.");
System.out.print(">");
choice = keyboard.nextInt();
tries++;
}
System.out.println("\nYou're right! Nice guess.");
System.out.println("It took you " + tries + " tries.");
}
}
Picture of the output