Advertisement
SaxSalute

Untitled

Feb 9th, 2012
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package austin.dailyprogrammer;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4. public class ReverseGuessingGame
  5. {  
  6.     public static void main(String [] args)
  7.     {
  8.         int bottom = 1, top = 100, computerNumber = 50;
  9.         Random random = new Random();
  10.         Scanner scanner = new Scanner(System.in);
  11.         boolean solved = false;
  12.         String words;
  13.         while(!solved)
  14.         {
  15.             System.out.print("Is your number " + computerNumber + "? (y - Yes, h - Higher, l - Lower): ");
  16.             words = scanner.nextLine();
  17.             if (words.equals("y"))
  18.             {
  19.                 System.out.println("I'm so good!");
  20.                 solved = true;
  21.             }
  22.             else if (words.equals("l"))
  23.             {
  24.                 top = computerNumber - 1;
  25.                 computerNumber = random.nextInt(top - bottom + 1) + bottom;
  26.             }
  27.             else if (words.equals("h"))
  28.             {
  29.                 bottom = computerNumber + 1;
  30.                 computerNumber = random.nextInt(top - bottom + 1) + bottom;
  31.             }
  32.             else
  33.                 System.err.println("\nStop it you joker.");
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement