-
Notifications
You must be signed in to change notification settings - Fork 51
/
Question_58_notfound.java
62 lines (52 loc) · 1.38 KB
/
Question_58_notfound.java
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
52
53
54
55
56
57
58
59
60
61
62
/*
Question 58
___________
*/
import java.util.*;
public class array {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[2 * n];
int[] arr1 = new int[100];
int num, reverse = 0;
int n1 = n;
for (int i = 0; i < n; i++) {
arr[i] = s.nextInt();
}
for (int i = 0; i < n; i++) {
System.out.print(arr[i] + " ");
}
for (int i = 0; i < n; i++) {
reverse = 0;
num = arr[i];
while (num != 0) {
int remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10;
}
arr[n1] = reverse;
n1++;
}
System.out.println();
for (int i = 0; i < n1; i++) {
System.out.print(arr[i] + " ");
}
int index = 0;
for (int i = 0; i < n1; i++) {
int flag = 0;
for (int j = 0; j < i; j++) {
if (arr[i] == arr[j]) {
flag = 1;
break;
}
}
if (flag == 0) {
arr1[index] = arr[i];
index++;
}
}
System.out.println();
System.out.println("Distinct numbers in array " + (index));
}
}