While Loops #65 (Well... that was easy!)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name:Number Guess Counter
/// File Name:NumberGuessCounter.java
/// Date Finished: 12/8/2015
import java.util.Random;
import java.util.Scanner;
public class NumberGuessCounter
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner input = new Scanner(System.in);
int x = 1 + r.nextInt(10), guess;
int count = 0;
System.out.print("I'm thinking of a number from 0 - 10. What is it? ");
System.out.print("Your guess: ");
guess = input.nextInt();
count++;
if ( guess != x && guess == 0) {
Random r = new Random();
int x = 1 + r.nextInt(100), guess;
System.out.println("You've sucessfully inputed the secret number");
System.out.println("");
System.out.print("Welcome to HARD mode. You now only have 1 try to guess the number. GOOD LUCK!");
guess = input.nextInt();
System.out.println("");
if (guess == x) {
System.out.println("You guessed it! What are the odds?!?");
} else if (guess > x) {
System.out.println("Sorry, you are too low. I was thinking of " + x);
}
else if (guess < x) {
System.out.println ("Sorry, you are too high. I was thinking of " + x);
} else {
System.out.println(" ERROR, restart the game and make a VALID answer ");
}
if (guess == x) {
System.out.println("That's right! My secret number was " + x + "!");
System.out.println("It only took you " + count + " tries.");
}
}
}
Picture(s) of the output