Assignment 65 and Counter
Code
///Matthew Hughs
///Period 5
///Counter
///Counter.java
///1/4/2016
import java.util.Scanner;
import java.util.Random;
class Counter
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System.in);
int guess;
int total = 0;
System.out.print("I have chosen a number between 1 and 10, guess what it is! ");
guess = keyboard.nextInt();
total++;
Random r = new Random();
int x = (1 + r.nextInt(10));
while (x != guess)
{
System.out.print("Nope try again ");
guess = keyboard.nextInt();
total++;
}
System.out.println("Congragulations, you guessed " + guess + " correctly.");
System.out.println("It only took you " + total + " times to get it.");
}
}
Picture of the output