Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package derp;
  2.  
  3. import java.lang.*;
  4. import java.io.*;
  5. import java.util.*;
  6.  
  7. public class Guessing {
  8.  
  9.     /**
  10.      * @param args
  11.      */
  12.     public static void main(String[] args) {
  13.         // TODO Auto-generated method stub
  14.         //Second job: computer guesses you
  15.        
  16.         Random random = new Random();
  17.         Scanner in = new Scanner(System.in);
  18.         int guess = 0;
  19.         int computerGuess = 0;
  20.         int computerGuessMax = 100;
  21.         int computerGuessMin = 0;
  22.         int previousGuess = 0;
  23.         System.out.print("Please tell me the upper limit of my guess: ");
  24.         int upper = in.nextInt();
  25.         int lower = 0;
  26.         int ranGen = random.nextInt(upper);
  27.        
  28.         while (guess == 0){
  29.             System.out.print("I have guessed "+ranGen+" as my number, did I guess right? 0 no or 1 for yes: ");
  30.             guess = in.nextInt();
  31.             if (guess == 0){
  32.                 System.out.print("higher or lower? 0 for lower and 1 for higher: ");
  33.                 computerGuess = in.nextInt();
  34.                 if(computerGuess == 0){
  35.                     //Removing the higher
  36.                     computerGuessMax = ranGen;
  37.                     ranGen = random.nextInt(computerGuessMax - computerGuessMin + 1) + computerGuessMin;
  38.                 }
  39.                 else{
  40.                     //Removing the lower
  41.                      computerGuessMin = ranGen;
  42.                      ranGen = random.nextInt(computerGuessMax - computerGuessMin + 1) + computerGuessMin;
  43.                 }
  44.                    
  45.             }
  46.            
  47.        
  48.         }
  49.        
  50.        
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement