Assignemnt #65
Code
///colin hinton
///5th period
///GuessingGame
///GuessingGame.java
///11/5/2015
import java.util.Scanner;
import java.util.Random;
class GuessingGame
{
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 it. ");
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("Congrats you guessed " + guess + " correctly.");
System.out.println("It only took you " + total + " times to guess it.");
}
}
Picture of the output