Assignemnt #55 Guess
Code
///Name: Joshua Pell
///Period: 6
///Project Name: Guess
///File Name: guess.java
///Date: 12/3/2015
import java.util.Scanner;
import java.util.Random;
public class guess
{
public static void main ( String[] args)
{
int n1,n2;
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
System.out.println("I'm Thinking of a number from 1 to 10");
System.out.print("Your guess:");
n1 = (1 + r.nextInt(10));
n2 = keyboard.nextInt();
if (n1==n2)
{
System.out.println("That's right! the number was " +n1);
}
else
{
System.out.println("Sorry, but I was Thinking of " +n1);
}
}
}
Picture of the output