Assignment #55
Code
///Name: Cody Swain
///Period: 6
///Project Name: WorstNumberGame
///File Name: WorstNumberGame.java
///Date: 11/9/15
import java.util.Random;
import java.util.Scanner;
public class NumberGame
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(10);
int guess;
System.out.println("I'm thinking of a number between 1-10 ");
System.out.println();
System.out.print("Yout Guess: ");
guess = keyboard.nextInt();
if (guess == secretNumber )
System.out.println("That's correct, my secret number was " + secretNumber );
else System.out.println( "Nope, I was actually thinking of " + secretNumber );
}
}
Picture of the output