Assignemnt #55 a Number-Guessing Game
Code
//tyler hart
//period 5
//A Number-Guessing Game
//guess.java
//11/6/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