我正在尝试制作两种方法,其他方法运行良好。问题是伪匹配计数器,其中输入应该是随机数,例如 5 4 3 2,用户猜测输入,例如 5 3 6 1,输出将是:伪匹配:1 和匹配:2。我不明白我的伪匹配方法哪里出错了。
public int match(int[] guess) //Counts the number of matches
{
int count = 0;
for(int i = 0; i<3; i++)
{
if (lotteryNumbers[i] == guess[i])
{
count++;
}
}
return count;
}
//First add psuedo counter for current program
//Then modify for multiple variables.
//Single slot to Single slot.
public int psuedoMatch(int[] guess)
{
boolean arraysEqual = true;
int psuedoCount = 0;
//Determine same size:
if (lotteryNumbers.length != guess.length)
{
arraysEqual = false;
}
//Determine if elements contain same data:
while (arraysEqual && psuedoCount < 3) // guess.length
{
if (lotteryNumbers[psuedoCount] != guess[psuedoCount] )
{
arraysEqual = false;
}
psuedoCount++;
}
return psuedoCount;
}