Assignemnt #72: Again with the Number-Guessing
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: NumberGuessingAgain
/// File Name: NumberGuessingAgain.java
/// Date Finished: 12/11/2015
import java.util.Scanner;
import java.util.Random;
public class NumberGuessingAgain
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int num = 1 + r.nextInt(10), guess;
int amt = 1;
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();
if (num != guess)
{
do
{
System.out.println("Nope, thats not the one. Guess again!");
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
amt++;
} while (num != guess);
}
System.out.println("Wow good job you dun guessed me number! It was " + num + "!");
System.out.println("It only took you " + amt + " tries!");
}
}
Picture of the output