Assignemnt #54 One Shot Hi-Lo
Code
///Name: JJ Deng
///Period: 6
///Program Name: One Shot Hi-Lo
///File Name: OneShot.java
///Date Finished: 12/3/15
import java.util.Random;
import java.util.Scanner;
public class Oneshot
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int user, num;
Random r = new Random();
num = 1 +r.nextInt(100);
System.out.println( "I'm thinking of a number between 1-100. Try to guess it." );
System.out.print( "> ");
user = keyboard.nextInt();
if ( user == num )
{
System.out.println( "You guessed it! What are the odds?!?!" );
}
else if ( user < num )
{
System.out.println( "Sorry you are too low. I was thinking of " + num );
}
else if ( user > num )
{
System.out.println( "Sorry, you ae too high. I was thinking of " + num );
}
}
}
Picture of the output