Assignment #55
Code
///jack newsom
///period 5
///program NumberGuess2
///filename NumberGuess2.java
///date completed 10/6/15
import java.util.Random;
import java.util.Scanner;
public class NumberGuess2
{
public static void main( String[] args )
{
Scanner numbot = new Scanner(System.in);
Random r = new Random();
System.out.println("I'm thinking of a number from 1 to 10.");
System.out.println("Try to guess what it is!");
int userInput = numbot.nextInt();
int answer = 1 + r.nextInt(10);
if ( userInput == answer )
System.out.println("That's right! My secret number was " + answer + "!");
else
System.out.println("Sorry, but I was really thinking of " + answer + ".");
}
}
Picture of the output