Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package derp;
- import java.lang.*;
- import java.io.*;
- import java.util.*;
- public class Guessing {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- //Second job: computer guesses you
- Random random = new Random();
- Scanner in = new Scanner(System.in);
- int guess = 0;
- int computerGuess = 0;
- int computerGuessMax = 100;
- int computerGuessMin = 0;
- int previousGuess = 0;
- System.out.print("Please tell me the upper limit of my guess: ");
- int upper = in.nextInt();
- int lower = 0;
- int ranGen = random.nextInt(upper);
- while (guess == 0){
- System.out.print("I have guessed "+ranGen+" as my number, did I guess right? 0 no or 1 for yes: ");
- guess = in.nextInt();
- if (guess == 0){
- System.out.print("higher or lower? 0 for lower and 1 for higher: ");
- computerGuess = in.nextInt();
- if(computerGuess == 0){
- //Removing the higher
- computerGuessMax = ranGen;
- ranGen = random.nextInt(computerGuessMax - computerGuessMin + 1) + computerGuessMin;
- }
- else{
- //Removing the lower
- computerGuessMin = ranGen;
- ranGen = random.nextInt(computerGuessMax - computerGuessMin + 1) + computerGuessMin;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement