Q:

write java program to compare between 2 arrays if they are similar or not

0

java program to compare between 2 arrays if they are equals or not

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now