Assignment #58
Code
/// Jonathan Stine
/// Period: 5
/// Program Name: One Shot Hi-Lo
/// File Name: OneShot.java
/// Date Finished: 1/19/16
import java.util.Scanner;
import java.util.Random;
public class OneShot {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
Random r = new Random();
int number, guess;
number = 1 + r.nextInt(100);
System.out.println( "I'm thinking of a number between 1-100. Try to guess it." );
System.out.print( "> " );
guess = keyboard.nextInt();
System.out.println();
if ( guess == number ) {
System.out.println( "You guess it! Noice." );
}
else if ( guess > number ) {
System.out.println( "Sorry, you are too high. I was thinking of " + number + "." );
}
else if ( guess < number ) {
System.out.println( "Sorry, you are too low. I was thinking of " + number + "." );
}
else {
System.out.println( "You suck at guessing." );
}
}
}
Code Output