Random Numbers #54 (Only physics tells you the answer)
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name:One Shot Hi-Lo
/// File Name: OneShotHiLo.java
/// Date Finished: 12/2/2015
import java.util.Random;
import java.util.Scanner;
public class OneShotHiLo
{
public static void main ( String[] args )
{
Random r = new Random();
Scanner input = new Scanner(System.in);
int x = 1 + r.nextInt(100), guess;
System.out.println("");
System.out.print("I'm thinking of a number between 1-100. Try to guess it.");
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 ");
}
}
}
Picture(s) of the output