Assignemnt #61, Keep Guessing
Code
/// Name: Alex Pinder
/// Period: 5
/// Program Name: Keep Guessing
/// File Name: prog61.java
/// Date Complete: 7/1/16
import java.util.Scanner;
import java.util.Random;
public class prog61
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int number, guess;
number = 1 + r.nextInt(10);
System.out.println( "Im thinking of a number from 1 to 10." );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
while ( guess != number )
{
System.out.println( "Sorry, but that wasn't my number. Guess again." );
System.out.print( "Your guess: " );
guess = keyboard.nextInt();
}
System.out.println( "You guessed right that was my secret number!" );
}
}
Picture of the output