Assignemnt #61 Keep Guessing
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Keep Guessing
///File Name: KG.java
///Date: 12/10/2015
import java.util.Scanner;
import java.util.Random;
public class KG
{
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.println("I'm thinking of a number from 1 to 10.");
System.out.print("Your guess: ");
guess = keyboard.nextInt();
System.out.println("");
while(guess != number)
{
System.out.println("Wrong! Guess again.");
guess = keyboard.nextInt();
}
System.out.println("That's right! My secret number was " + number);
}
}
Picture of the output