Previously we Have Discussed the Program for
Here we learn the program to find the common elements from two array using for loop.
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("Array 1 Elements :");
for(int i : input1){ // This loop only prints array 1 elements
System.out.print(i+",");
}
System.out.println("\n\nArray 2 Elements :");
for(int i : input2){ // This loop only prints array 2 elements
System.out.print(i+",");
}
System.out.println("\n\nCommon 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:
Array 1 Elements :
4,5,9,8,2,6,3,
Array 2 Elements :
4,2,6,0,1,
Common Elements In Both Arrays :-
4
2
6
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.
This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.
Java I/O Tutorial

No comments:
Post a Comment