Assignemnt #61 and Keep Guessing
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: KeepGuessing
/// File Name: KeepGuessing.java
/// Date Finished: 1/5/2016
import java.util.Random;
import java.util.Scanner;
public class KeepGuessing {
public static void main( String[] args ) {
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(10);
int guess;
System.out.println("I'm thinking of a number between 1-10 ");
System.out.println();
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
while ( guess != secretNumber ){
System.out.println("Sorry, guess again: ");
guess = keyboard.nextInt();
}
System.out.println("That's it! My secret number was " + secretNumber );
}
}
prog61.PNG