One Shot Hi-Lo
import java.util.Scanner;
import java.util.Random;
public class one
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int choice;
int number;
number = 1 + r.nextInt(100);
System.out.println("Im thinking of a number between 1-100. Try and guess it");
System.out.println(">");
choice = keyboard.nextInt();
if ( choice < number )
{
System.out.println("Sorry, to low. The number was " + number );
}
else if ( choice > number )
{
System.out.println("Nope, to high. The numer was " + number );
}
else if ( choice == number )
{
System.out.println("Wow! How'd you know! It was " + number + " !");
}
}
}
Picture of the output