Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Evan Hopkins
- * Comp Sci
- * Reverse Guessing Game 6-2
- */
- import java.util.Scanner;
- public class ReverseGuessingGame {
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- int number = 50, guess = 0, lcv = 0;
- int attempts = 0;
- int max = 100;
- int min = 1;
- System.out
- .println("You are going to play me (the computer) in a guessing game. Enter "
- + "the number you would like me to guess and i will tell you how many tries "
- + "it takes me to get it. To help me, i will know whether the number is higher"
- + "or lower than my previous guess.");
- number = reader.nextInt();
- while ((guess != number) && (lcv < 7)) {
- guess = Math.round(((max + min) / 2));// rounds the average of the
- // min and max possibilities
- System.out.println(guess);// prints all guesses
- if (guess > number)
- max = guess;
- else
- // guess is less than number
- min = guess;
- lcv++;
- attempts++;
- }
- if (lcv > 7) {
- guess = 100;
- attempts = 7;
- System.out.println(guess);// prints guess
- }
- System.out.println("The number is " + guess + " and it took me "
- + attempts + " tries to get it.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement