Assignment #58
Code
/// Gian Adoremos
/// Period: 7
/// Program Name: FiftyEith Program
/// File Name: OneShotHiLo.java
/// Date Finished: 11/19/2015
import java.util.Random;
import java.util.Scanner;
public class OneShotHiLo
{
public static void main(String[] args)
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int secretNumber = 1 + r.nextInt(100);
int guessNumber;
System.out.println("I'm thinking of a number between 1-100. Try to guess it.");
guessNumber = keyboard.nextInt();
System.out.println();
if (guessNumber == secretNumber)
System.out.println("You guessed it! What are the odds?");
else if (guessNumber > secretNumber)
System.out.println("Sorry, you are too high. I was thinking of " + secretNumber + ".");
else if (guessNumber < secretNumber)
System.out.println("Sorry, you are too low. I was thinking of " + secretNumber + ".");
else
System.out.println("What?");
}
}
Picture of the output