-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample.java
More file actions
61 lines (41 loc) · 959 Bytes
/
Copy pathSample.java
File metadata and controls
61 lines (41 loc) · 959 Bytes
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
package catchup;
import java.util.Scanner;
public class Sample {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int size = sc.nextInt();
int arr[] = new int[size];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
// sorting an array
int temp;
for (int i = 0; i < size - 1; i++) {
for (int j = i + 1; i < size; j++) {
if (arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
// identify the duplicate
boolean duplicate = false;
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; i < arr.length; j++) {
if (arr[i] == arr[j]) {
duplicate = true;
}
}
}
if (duplicate) {
System.out.println("duplicate is present");
} else {
System.out.println("duplicate is not present");
}
// print the array
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i] + " ");
}
}
}