Assignemnt #61 Keep Guessing
Code
//tyler hart
//period 5
//A Number-Guessing Game
//guess.java
//11/6/2015
import java.util.Scanner;
import java.util.Random;
public class guess2
{
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();
while ( n1 != n2 )
{
System.out.println("That is incorrect. Guess again.");
System.out.print("Your guess: ");
n2 = keyboard.nextInt();
}
if (n1==n2)
{
System.out.println("That's right! the number was " +n1);
}
}
}
Picture of the output