Assignment #55 and A Number-Guessing Game
Code
/// Name: Lauren Baird
/// Period: 7
/// Program Name: A Number-Guessing Game
/// File Name: GuessingGame.java
/// Date Finished: 10/30/2015
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 guess;
int number = 1 + r.nextInt(10);
System.out.println();
System.out.print( "I'm thinking of a number from 1-10. Try and guess. " );
guess = keyboard.nextInt();
if (guess == number)
{
System.out.println( "You got it! It was " + number + "!" );
}
else
{
System.out.println( "Nope. It was " + number + "." );
}
}
}