Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method that takes two string arrays as input parameters and returns a bo

ID: 3536056 • Letter: W

Question

Write a method that takes two string arrays as input parameters and returns a boolean value indicating if the strings in corresponding locaitons of the two arrays are identical or not.

Ok so I have been working on this problem and I thought I had got it until I ran the program and it doesn't do anything. Can anyone please tell me what I am doing wrong?

public class StringArrays {

public static void main(String [] args) {

String[] a = {"Gold", "Blue", "Pink", "Green", "Orange"};
String[] b = {"Red", "Yellow", "Pink", "Blue", "Orange"};

identical(a, b);
}

public static boolean identical(String[] c, String[] d) {
for (int i = 0; i < c.length; i++) {
if (c[i].equals(d[i]))
return true;
}
return false;
}
}

Explanation / Answer

please rate - thanks you had 2 problems-never output anything, and returned true as soon as you got a match. I fixed the code, and added another array and comparison, to show 1 where it's true, and 1 where it's false public class StringArrays { public static void main(String [] args) { String[] a = {"Gold", "Blue", "Pink", "Green", "Orange"}; String[] b = {"Red", "Yellow", "Pink", "Blue", "Orange"}; String[] c = {"Red", "Yellow", "Pink", "Blue", "Orange"}; System.out.println(identical(a, b)); System.out.println(identical(c, b)); } public static boolean identical(String[] c, String[] d) { for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote