Program #58

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: One Shot Hi-Lo
    /// File Name: Shot.java
    /// Date Finished: 12/1/2015 public class Shot

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

Picture of the output

Assignment 58