Single Post

Header

Monday, December 21, 2015

Print which values are not present in the second Array

Find which values are not present in the second Array

public class NotPresentInSecondArray {

public static void main(String args[]) {
int[] array1 = {1,2,3,4,5};
int[] array2 = {2,3,1,0,5};
int j;
for (int i=0; i<array1.length;i++) {
int count = 0;
for (j=0; j<array2.length; j++) {
if (array1[i] == array2[j]) {
break;
}
count++;
}
if (count == array2.length) {
System.out.println("The value which is not present in the second array is "
+ array2[i]);
}
}
}
}

Output:
The value which is not present in the second array is 0



No comments:

Post a Comment