Below Example shows how to find common elements from two input arrays.
public class CommonElementsFromTwoArray {
public static void main(String[] args) {
int[] input1 = {4,5,9,8,2,6,3};
int[] input2 = {4,2,6,0,1};
System.out.println("Common Elements In Both Arrays :-");
for(int i=0; i<input1.length; i++){
for(int j=0; j<input2.length; j++){
if(input1[i] == input2[j]){
System.out.println(input1[i]);
}
}
}
}
}
Program Output :-
Common Elements In Both Arrays :-
4
2
6
public class CommonElementsFromTwoArray {
public static void main(String[] args) {
int[] input1 = {4,5,9,8,2,6,3};
int[] input2 = {4,2,6,0,1};
System.out.println("Common Elements In Both Arrays :-");
for(int i=0; i<input1.length; i++){
for(int j=0; j<input2.length; j++){
if(input1[i] == input2[j]){
System.out.println(input1[i]);
}
}
}
}
}
Program Output :-
Common Elements In Both Arrays :-
4
2
6
No comments:
Post a Comment