Assignemnt #61: Keep Guessing
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: KeepGuessing
/// File Name: KeepGuessing.java
/// Date Finished: 12/4/2015
import java.util.Scanner;
import java.util.Random;
public class KeepGuessing
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int num = 1 + r.nextInt(10), guess;
System.out.println("I'm thinking of a number from 1 to 10. Can you guess what it is?");
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
System.out.println();
while (num != guess)
{
System.out.println("Nope, thats not the one. Guess again!");
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
}
System.out.println("Wow good job you dun guessed me number! It was " + num + "!");
}
}
Picture of the output