Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

countCommon

Language/Type: Java arrays
Author: Jessica Miller (on 2010/12/28)

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.