Assignemnt #55 and Number Guessing Game
Code
///Name: Ben Borglin
///Period: 6
///Program name: Guessing Game
///file name: GuessingGame.java
///Date Finsihed: 10/16/15
import java.util.Scanner;
import java.util.Random;
public class GuessingGame
{
public static void main ( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice, x;
x = 1 + r.nextInt(10);
System.out.println("Im thinking of a number between 1 to 10.");
System.out.print("Your Guess: ");
choice = keyboard.nextInt();
if ( x == choice )
System.out.println("Thats right! My secret number was " + x);
else if ( x < 1 || choice > 10)
System.out.println("Your choice must be between 1-10");
else
System.out.println("Sorry, my number was " + x + ".");
}
}
Picture of the output