Keep Guessing
import java.util.Scanner;
import java.util.Random;
public class kee
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int guess, number;
number = 1 + r.nextInt(10);
System.out.print( "Im thinking of a number from 1-10. Try to guess it: " );
guess = keyboard.nextInt();
System.out.println();
while ( guess != number )
{
System.out.println("Sorry, try again");
guess = keyboard.nextInt();
}
System.out.println("About time :)");
}
}
Picture of the output