【发布时间】:2020-10-22 07:04:48
【问题描述】:
我已经设置了一个数组来随机化一个类中的 5 个不同的数字。在另一个类中,我提示用户猜测随机数,并且每次都必须参考该数字以确定他们是否猜对了。我的问题是被随机化的数字在数据类型 int[] 中,我需要将它们与数据类型 int 进行比较。当尝试引用随机数时,我收到错误“类型不匹配:无法从 int[] 转换为 int”。关于我将如何做到这一点的任何建议?
类 diceNumGen
final static int ARRAY_SIZE = 5;
public static int[] randNumArray = new int [ARRAY_SIZE];
public static int[] randNums(){
for(int i=0; i < randNumArray.length; i++) {
randNumArray[i] = (int) (Math.random()*12);
System.out.println(randNumArray);
}
return randNumArray.clone();
}}
班级投注
static Bet bet = new Bet();
diceNumGen newClassObj = new diceNumGen();
int secondArray = diceNumGen.randNumArray;
//Set Turns variable where turns = 5
public int turnsToGo = 5;
//Set up the bet() method
public void bet() {
//Sets up the options as an array to be on the JOptionPane, each are numbered 0, 1, and 2 respectively
String[] options = {"Guess below 7", "Guess 7", "Guess above 7"};
【问题讨论】:
标签: arrays types converters type-mismatch