-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayprob.java
More file actions
51 lines (51 loc) · 1.48 KB
/
arrayprob.java
File metadata and controls
51 lines (51 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package mypack;
import java.util.Scanner;
public class arrayprob {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n,m;
Scanner input=new Scanner(System.in);
System.out.println("Enter no. of elements to store in 1st no");
n=input.nextInt();
System.out.println("Enter elements of array of 1st no");
int a[]=new int[10];//Create array of memory length 10
for(int i=0;i<n;i++) {
a[i]=input.nextInt();//Storing element in a[i] array
}
System.out.println("Enter no. of elements to store in 2nd no");
m=input.nextInt();
System.out.println("Enter elements of array of 2nd no");
int b[]=new int[10];//Create array of memory length 10
for(int i=0;i<m;i++) {
b[i]=input.nextInt(); //Storing element in b[i] array
}
System.out.println("Unmatched values between two arrays are as follows");
/*The logic is user compare match values & break out of if loop & print unmatch values
stored in "isElementPresent" via boolean operation*/
for(int i=0;i<a.length;i++) {
boolean isElementPresent= false;
for(int j=0;j<b.length;j++) {
if(a[i]==b[j]) {
isElementPresent= true;
break;
}
}
if(!isElementPresent) {
System.out.print(a[i]+";");
}
}
System.out.println();
for(int i=0;i<b.length;i++) {
boolean isElementPresent= false;
for(int j=0;j<a.length;j++) {
if(b[i]==a[j]) {
isElementPresent= true;
break;
}
}
if(!isElementPresent) {
System.out.print(b[i]+";");
}
}
}
}