Assignment #58 and One Shot Hi-Lo
Code
//Name: Mark Katz
///Period: 6
///Program Name: A Number-Guessing Game
///File Name: randomnumbergame.java
///Date Finished: 10/21/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 guess, r1;
Random r = new Random();
r1 = 1 +r.nextInt(100);
System.out.println( "I'm thinkin of a number between 1-100. Try to guess it." );
System.out.print( "> ");
guess = keyboard.nextInt();
if ( guess == r1 )
{
System.out.println( "You guessed it! What are the odds?!?!?!" );
}
else if ( guess < r1 )
{
System.out.println( "Sorry you are too low. I was thinking of " + r1 );
}
else if ( r1 < guess )
{
System.out.println( "Sorry, you ae too high. I was thinking of " + r1 );
}
}
}
Picture of the output