Assignemnt #69

Code

/// Name: Connor Siri
/// Period: 7
/// Program Name: Reverse
/// File Name: Reverse.java
/// Date Finished: 11/05/2015

import java.util.Random;
import java.util.Scanner;

public class Reverse
{
    public static void main( String[] args )
    {
        Random r = new Random();
    Scanner keyboard = new Scanner(System.in);
    int hi = 1000;
    int low = 1;
    int average = (hi + low)/2;
    String x;
    
    System.out.println("Think of a number between 1 and 1000 and i will try and guess it.");
    System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
    System.out.print("> ");
    x = keyboard.next();
    System.out.println("");
    
    while (!x.equals("c"))
    {
    if (x.equals("h"))
    {
    hi = average;
    average = (hi + low)/2;
    System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
    System.out.print("> ");
    x = keyboard.next();
     System.out.println("");
    }
    else if (x.equals("l"))
    {
    low = average;
    average = (hi + low)/2;
    System.out.println("My guess is " + average + ". Am i to (h)igh, to (l)ow, or (c)orrect");
    System.out.print("> ");
    x = keyboard.next();
     System.out.println("");
    }
    }
    
    System.out.println("I got it. I am the best at guessing");
    
   
       
    }
    }
    

Picture of the output

Assignment9.html