countCommon

Category: Arrays
Author: Jessica Miller and Marty Stepp
Book Chapter: 7.2
Problem: countCommon
Write a static method named countCommon that accepts three arrays of strings as parameters and returns an integer
count of how many indexes store exactly the same string in all three arrays. For example, if the arrays are:
// index
0
1
2
3
4
5
6
7
String[] a1 = {"hi", "Ed", "how", "are", "you", "folks", "DoIng", "today?"};
String[] a2 = {"hi", "Bob", "how", "are", "YOUR", "kids", "doing", "today?"};
String[] a3 = {"hi", "you", "how", "are", "you", "guys", "DOING", "today?"};
Then the call of countCommon(a1, a2, a3) should return 4 because indexes 0, 2, 3, and 7 store exactly the same
string in all three arrays. Indexes 1, 4, 5, and 6 do not. (Index 6 differs by capitalization.)
The arrays might not be the same length. An index must be within the bounds of all three arrays to be considered.
For example, given the arrays below, the call of countCommon(a4, a5, a6) should return 3 because all three
arrays store the same values at indexes 0, 2, and 5:
// index
0
1
2
3
4
5
6
7
String[] a4 = {"hi", "Ed", "how", "ARE", "you", "Doing", "I'm", "fine"};
String[] a5 = {"hi", "Bob", "how", "are", "YOU", "Doing"};
String[] a6 = {"hi", "you", "how", "is", "you", "Doing", "this", "fine", "day?"};
For full credit, do not modify the elements of the arrays passed in. Do not make any assumptions about the length of
the arrays or the length of the strings stored in them. You may assume that none of the arrays or elements are null.