This is a beta version of Practice-It. Give us feedback

logo Practice-It logo

countCommon

Language/Type: Java arrays
Author: Jessica Miller (on 2018/05/01)

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.

Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.