Assignment #52

Code

  /// Name: Sam Wilson
  /// Period: 6
  /// Program Name: athousandshots
  /// File Name: athousandshots.java
  /// Date Finished: 12/1/2015

          import java.util.Random;
    import java.util.Scanner;
    
    public class athousandshots
    {
        public static void main(String[] args)
        {
            Scanner keyboard = new Scanner(System.in);
            
            int guess, g1;
            
            
            Random r = new Random();
            
            g1 = 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 == g1 )
            {
                System.out.println( "You guessed it!" );
            }
            else if ( guess < g1 )
            {
                System.out.println( "Sorry you are too low. I was thinking of " + g1 );
            }
            else if ( g1 < guess )
            {
                System.out.println( "Sorry, you guessed too high. I was thinking of " + g1 );
            }
        }
    }

    

Picture of the output

Assignment 31