-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniqueArrayElements.java
More file actions
44 lines (39 loc) · 954 Bytes
/
uniqueArrayElements.java
File metadata and controls
44 lines (39 loc) · 954 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
//printing unique values from an integer array
// 5
// 2 2 2 2 2
// 2
import java.util.*;
import java.util.Scanner;
class uniqueArrayElements {
public static void main(String[] args) {
Scanner s= new Scanner(System.in);
int n;
n=s.nextInt();
int[] arr=new int[n];
int i, j;
for(i=0; i<n; i++){
arr[i]=s.nextInt();
}
int[] temp=new int[n];
int tmp;
for(i=0; i<n; i++){
for(j=0; j<(n-i-1); j++){
if(arr[j]>arr[j+1]){
tmp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=tmp;
}
}
}
for(i=0; i<n; i++){
System.out.print(arr[i]+"\t");
}
System.out.println();
for(i=0; i<n; i++){
while(i<n-1 && arr[i]==arr[i+1]){
i++;
}
System.out.print(arr[i]+"\t");
}
}
}