Assignment #68

Code

 ///Name: Conner Wygaerts
///Period: 6
///Project Name: ReverseHiLo
///File Name: ReverseHiLo.java
///Date Finished: 12/16/15

import java.util.Scanner;

public class ReverseHiLo
{
	public static void main ( String[] args )
	{
        
            Scanner keyboard = new Scanner(System.in);
            
            int hi = 1000;
            int lo = 1;
            int x = (hi + lo)/2;
            String response;
            
            System.out.println("Think of a number from 1 to 1000. I'll try to guess it.");
            System.out.println("My guess is " + x + ". Am I too high, too low, or correct?");
            response = keyboard.next();
            
            while (! response.equals("correct"))
            {
                if (response.equals("high"))
                    hi = x;
                else if (response.equals("low"))
                    lo = x;
                
                x = (hi + lo)/2;
                
                System.out.println("My guess is " + x + ". Am I too high, too low, or correct?");
                response = keyboard.next();
            }
            
            System.out.println("Ha! I am the greatest guesser in the WORLD!");
        }
    }

Picture of the output

YourInitials.html