Assignment #66

Code

    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: HiLoGuessingGame
    ///File Name: HiLoGuessingGame.java
    ///Date: 12/3/15
    
    import java.util.Scanner;
    import java.util.Random;
    
    public class HiLoGuessingGame
    {
        public static void main( String[] args  )
        {
            Scanner keyboard = new Scanner(System.in);
            Random r = new Random();
            int  guesses = 1, MaxGuesses = 7, guess;
            int rnumber = 1 + r.nextInt(100);
            
            
            System.out.println( "I'm thinking of a number between 1-100. You have 7 guesses. ");
            System.out.print( "First guess: ");
            guess = keyboard.nextInt();
            
            while ( guesses < MaxGuesses && guess != rnumber )
            {
                if ( guess < rnumber){
                    System.out.println("Sorry. you are too low.");
                }
                else if ( guess > rnumber ){
                    System.out.println("Sorry, you are too high");
                }
                
                guesses++;
                System.out.print( "Guess # " + guesses + "  " );
                guess = keyboard.nextInt();
            }
            
            if ( guess == rnumber )
                System.out.println( "You guessed it! What are the odds?!? ");
            else System.out.println("Sorry, you didn't guess it in 7 times. You are stupid");
            
        }
    }

        
    

Picture of the output

Assignment 66 Assignment 66