I’m trying to make two methods, the other methods are running fine. The trouble is a pseudo match counter where an input should be the random number eg 5 4 3 2 and the user guess input eg 5 3 6 1 and the output would be: Pseudo match: 1 and matches: 2. I’m not understanding where I’m going wrong in my Pseudo Match method.
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;
}
I guess you are trying to find the number of matches of these 2 arrays,
but the relative index of the equal elements should be different so that we can add them to the pseudo counter mechanism. So take a look at this method and try it: