java program to compare between 2 arrays if they are equals or not
public class Main { public static void main(String[] args) { int[] array1 = {10, 20, 30, 60, 80, 100}; int[] array2 = {10, 20, 30, 60, 80, 100}; boolean equavalent=true; if(array1.length==array2.length) //checking if elements count is equavalent { for(int i=0; i < array1.length ; i++) if(array1[i]!=array2[i]) { System.out.println("the arrays are not equavalent"); equavalent=false; break; } if(equavalent==true) System.out.println("the arrays are equavalent"); } else{ System.out.println("the arrays are not equavalent"); } } }
output:
--------
the arrays are equavalent
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
output:
--------
the arrays are equavalent
need an explanation for this answer? contact us directly to get an explanation for this answer