我必须编写一个代码,让用户猜测计算机选择的数字。我还需要使用布尔值 true 或 false 来告诉用户用户是否正确。我尝试使用 if else 语句,但我还没有在 Java 中学习这一点。这是我到目前为止所拥有的:
import java.util.*;
public class RandomGuessMatch
{
public static void main(String[] args) {
boolean right = true;
int MAX = 5;
int MIN = 1;
int guess;
int random;
Scanner ask = new Scanner(System.in);
System.out.println("Input your guess between 1 through 5.");
guess = ask.nextInt();
random = MIN + (int)(Math.random() * MAX);
System.out.println("Your guess was " + guess);
System.out.println("The random number was " + random);
if (right =
}
}
繁花如伊
白猪掌柜的
相关分类