Hello Coders i just registered and i love this site , i think i ll be here more often.
i have a question that i couldn't solve i'm new at java here is the question ;
Write a Java method called identical that takes 2 arrays of integers as arguments. The method should return true if the 2 arrays are identical; false otherwise. Hint: Two arrays are considered to be identical if they have the same length and the same values in the same order.
b. Include your method in part a) into a Java program that initializes two arrays, invokes (calls) the method identical to check if the two arrays are identical or not and print a suitable message.
And here is my code
public class identicalMethod { public static void main(String[] args){ int[] array = {1,2,3,4,5}; int[] array2 = {1,2,3,4,10}; if (identical(array, array2)) System.out.println("Its identical"); else System.out.println("its not"); } public static boolean identical(int[] a , int[] b) { boolean result = false ; for (int i = 0; i <a.length; i++){ if(a[i] == b[i]) result = true; } return result; } }
It always telling me that it's identical but it's not