-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNeighborNumbers.java
More file actions
43 lines (43 loc) · 1.09 KB
/
NeighborNumbers.java
File metadata and controls
43 lines (43 loc) · 1.09 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
/*Given two strings as input, write a program to find which numbers from the first string are present in the second string. Print the result as a string containing the
matched numbers in ascending order.
For example:
Input:
"12, 13, 15, 19, 212, 556, 2146"
"13, 44, 432, 12, 788, 246, 2146, 46"
Output: "12, 13, 2146"
*/
import java.util.*;
public class NeighborNumbers
{
public static void main(String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Enter the size of the First array");
int size=in.nextInt();
int arr[]=new int[size];
System.out.println("Enter the elements");
for(int i=0;i<size;i++)
{
arr[i]=in.nextInt();
}
System.out.println("Enter the size of the Second array");
int size2=in.nextInt();
int arr2[]=new int[size2];
System.out.println("Enter the elements");
for(int i=0;i<size2;i++)
{
arr2[i]=in.nextInt();
}
System.out.println("Neighbor Numbers are:");
for(int i=0;i<size;i++)
{
for(int j=0;j<size2;j++)
{
if(arr[i]==arr2[j])
{
System.out.println(arr[i]);
}
}
}
}
}