Assignment #58
Code
/// Name: Ian Stanko
/// Period: 5
/// Program Name: OneShot
/// File Name: OneShot.java
/// Date Finished: 11/23/2015
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 are too high. I was thinking of " + r1 );
}
}
}
Picture of the output