# Counting Matches in Parallel Arrays

• January 31st, 2012, 09:54 PM
dx8292
Counting Matches in Parallel Arrays
I want to make a method involving arrays.
Both are Integer Arrays. (And are the same size, so I don't need to check if it's the same size)
Its needs see how many of the parallel positions matches there are.
I know what's needed, but don't know how to really put it together.
int[] arrayone=new int[10];
int[] arraytwo=new int[10];

The code above I do not want in the method.

public static void Count(int?? confused hear)
{

if (arrayone[i] ==arraytwo[i])
variable=true;

some accumulator might be needed

return match;
}

What I have above might be on the right track, but wrong in terms of implementation.
Noob in Java. Still trying to get a feel for methods and arrays.

What I have above doesn't count the number of times the values in the corresponding positions are the same; it just indicates if the value in the corresponding position is the same. Not sure how to count it.

Any suggestions would be great.

Forgot to add the for loop but don't worry about that part.
• January 31st, 2012, 10:13 PM
rchrispink3913
Re: Counting Matches in Parallel Arrays
Something like this?

public static void main(String[] args) {
int[] arrayone = new int[10];
int[] arraytwo = new int[10];
int matches=0;
matches = count(arrayone,arraytwo);
System.out.println(matches);
}

public static int count(int[] a, int[] b) {
int match = 0;
for (int i = 0; i < a.length; i++) {
if (a[i] == b[i])
match++;
}
return match;
}
}
• January 31st, 2012, 10:58 PM
dx8292
Re: Counting Matches in Parallel Arrays
I had something different in mind, but just by looking it seems right. I'll play around with the code tomorrow cause I'm tired right now, too much coding today, but good practice. I'll post back tomorrow after I finish some Visual Basic stuff and let you know how it worked out, but either way THANK YOU, I appreciate it.
• February 1st, 2012, 08:45 AM
copeg
Re: Counting Matches in Parallel Arrays