-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram3.java
More file actions
62 lines (36 loc) · 1.15 KB
/
program3.java
File metadata and controls
62 lines (36 loc) · 1.15 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
52
53
54
55
56
57
58
59
60
61
/*
Write the program to print the distict element from the array.
*/
package LeetCode;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class program3 {
public static void main(String[] args)throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int size= Integer.parseInt(br.readLine());
System.out.println("Enter the size of the array: ");
int a[] = new int[size];
System.out.println("Enter the element of the array: ");
for(int i=0;i<a.length;i++){
a[i] = Integer.parseInt(br.readLine());
}
for(int i=0;i<a.length;i++){
for(int j=i+1;j<a.length;j++){
if(a[i] > a[j]){
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
int i=0;
for( i=1;i<=a.length-1;i++){
if(a[i] !=a[i-1]){
System.out.print(a[i-1]+" ");
}
}
if(a[a.length-1]!=a[a.length-2]){
System.out.print(a[a.length-1]+" end");
}
}
}