저는 현재 Java 1 클래스에 있으며 재미있는 게임을 추측합니다. 기본 테이크 입력은 너무 높거나 낮 으면 알려주고 다시 추측 할 수있게 해줍니다. 나는 컴퓨터가 추측 할 수있게 만드는 것이 흥미로울 것이라고 생각하고 추측을 그것과 비교합니다. 나는 모든 세대를 가지고 일하는 것을 비교하지만, 더 큰 것을 고려하지 않고 숫자를 추측한다. 내가 가진 :이전 난수보다 크거나 작은 난수를 생성하려면 어떻게해야합니까?
public static void autoPlay(int num){
Random rand = new Random();
int guess1 = rand.nextInt(100) + 1;
int counter = 0;
while(guess1 != num){
counter++;
int guess = rand.nextInt(100) + 1;
int initialHigh = 100;
int initialLow = 0;
// I want it to guess smart and recognize if it were too high or too low, and generate a number between there
if(guess1 > num){
int newGuess = rand.nextInt(initialHigh - guess1) + 1;
}else if(guess1 < num){
int newGuess2 = rand.nextInt(initialLow + guess1) + 1;
}
initialLow = guess;
initialHigh = guess;
guess1 = guess;
System.out.printf("%3d", guess1);
}
System.out.println("It took " + counter + " guesses to get the correct number");
}
나는 문 경우, 또는 경우 프로그래머 내 수학 나는 그렇게 호출 할 수 있습니다 뭔가 잘못이 무엇인지 말할 수 없다. 당신이 중복을 피하려면