Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
1.1 kB
2
Indexable
import java.util.*;
public class problem01 {
    public static int generateNum(int a,int b){
        return (int)Math.floor(Math.random()*(a-b+1)+b);
    }
    public static boolean check(int c,int d){
        boolean a = false;
        if(c==d){
            a=true;
        }
        return a;
    }
    public static void main(String[]args){
        System.out.println("Please write the maximum numbers on the guessing game");
        Scanner input = new Scanner(System.in);
        int max = input.nextInt();
        System.out.println("Write your secret number and let the computer guess it");
        final int rez = input.nextInt();
        boolean c = false;
        int min = 0;
        while (c) {
            int number = generateNum(max, min);
            c = check(number,rez);
            if(c==false&&number<rez){
                min=number;
            }
            else if(c==false&&number>rez){
                max=number;
            }
        }
        System.out.println("The computer found yor number and it is: "+rez);

    }
}