Assignment #58: One-Shot Hi-Lo
Code
/// Name: Kiran O'Farrell
/// Program Name: One Shot Hi-Lo
/// File Name: OneShotHiLo.java
/// Date Completed: 12/3/15
import java.util.Scanner;
import java.util.Random;
public class OneShotHiLo {
public static void main(String[] args) {
Random r = new Random();
Scanner keyboard = new Scanner (System.in);
int secret = 1 + r.nextInt(100);
int guess;
System.out.println("I'm thinking of a number from 1-100.");
guess = keyboard.nextInt();
if (guess > secret) {
System.out.println("Sorry, your guess was too high.");
}
else if (guess < secret) {
System.out.println("Sorry, your guess was too low.");
}
else if (guess == secret) {
System.out.println("Congratulations! you guessed correctly!");
}
}
}
Picture of the output