An Awesome program: Common elements in two arrays
Program: Common elements in two arrays: solved Java program for ICSE Class 10 Computer Applications with complete BlueJ code, explanation and sample output.
Write a program to accept two integer arrays from the user and print all the common elements in two arrays.
String programs
import java.io.*;
class common {
public static void main()throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the size of the first array");
int n=Integer.parseInt(br.readLine());
int Arr1[]=new int[n];
System.out.println("Enter the values");
for(int i=0;i<n;i++)
Arr1[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the size of the second array");
int o=Integer.parseInt(br.readLine());
int Arr2[]=new int[o];
System.out.println("Enter the values");
for(int i=0;i<o;i++)
Arr2[i]=Integer.parseInt(br.readLine());
boolean flag=false;
for(int i=0;i<n;i++)
{
for(int j=0;j<o;j++)
{
if(Arr1[i]==Arr2[j])
{
System.out.print("THE COMMON ELEMENTS ARE-"+Arr1[i]+"\t");
flag=true;
}
}
}
System.out.println();
if(flag==false)
System.out.println("THERE ARE NO COMMON ELEMENTS");
}
}Output:
Enter the size of the first array
4
Enter the values
1
2
3
4
Enter the size of the second array
5
Enter the values
2
4
6
8
10
THE COMMON ELEMENTS ARE- 2
THE COMMON ELEMENTS ARE- 4
JAVA videos
Related Posts
Continue learning with these related articles

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.