Skip to content

Instantly share code, notes, and snippets.

@eroberer
Created May 2, 2017 22:46
Show Gist options
  • Select an option

  • Save eroberer/c079f0c82e9a395f6cea0770ee3dfab5 to your computer and use it in GitHub Desktop.

Select an option

Save eroberer/c079f0c82e9a395f6cea0770ee3dfab5 to your computer and use it in GitHub Desktop.
public class Difference {
public static void main(String[] args) {
int []array1 = {1,2,3,4,5};
int []array2 = {4,5,6,7};
System.out.print("The difference is {");
difference(array1,array2);
difference(array2,array1);
System.out.println("}");
}
public static void difference(int[]arr1, int[]arr2){
for(int i = 0; i < arr1.length; i++){
boolean comp = false;
for(int j = 0; j < arr2.length; j++){
if(arr1[i] == arr2[j]) comp = true;
}
if(!comp) System.out.print(arr1[i] + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment