Assignemnt #58, One Shot Hi-Lo
Code
/// Name: Alex Pinder
/// Period: 5
/// Program Name: One Shot Hi-Lo
/// File Name: prog58.java
/// Date Complete: 1/4/16
import java.util.Scanner;
import java.util.Random;
public class prog58
{
public static void main( String[] args )
{
Random r = new Random();
Scanner keyboard = new Scanner(System.in);
int answer, guess;
answer = 1 + r.nextInt(100);
System.out.print( "Guess a number between 1 and 100\nGuess: " );
guess = keyboard.nextInt();
if ( guess > answer )
System.out.println( "Nice try but too high." );
else if ( guess < answer )
System.out.println( "Nice try but too low." );
else if ( guess == answer )
System.out.println( "You Guessed It! Nice!" );
}
}
Picture of the output