Assignemnt #65: Number-Guessing with a Counter
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: GuessingGameWithCounter
/// File Name: GuessingGameWithCounter.java
/// Date Finished: 12/7/2015
import java.util.Scanner;
import java.util.Random;
public class GuessingGameWithCounter
{
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();
while (num != guess)
{
System.out.println("Nope, thats not the one. Guess again!");
System.out.print("Your Guess: ");
guess = keyboard.nextInt();
amt++;
}
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