-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNumber.java
More file actions
35 lines (22 loc) · 812 Bytes
/
Number.java
File metadata and controls
35 lines (22 loc) · 812 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
import java.util.*;
public class Number {
public static void main (String [] args){
int [] a = {51, 1, 2, 7, 8 , 9, 13, 2, 14, 2,52, 33, 7};
calculate(a);
}
public static void calculate(int [] a){
Map<Integer, ArrayList<Integer>> m = new HashMap<>();
ArrayList<Integer> FreqArray = new ArrayList<Integer>();
for(int i = 0; i < a.length; i++){
if(m.get(a[i]) == null) {m.put(a[i], new ArrayList<Integer>());}
m.get(a[i]).add(i+1);
}
Set set = m.entrySet();
Iterator i = set.iterator();
while(i.hasNext()){
Map.Entry me = (Map.Entry)i.next();
System.out.print(me.getKey() + "::");
System.out.print((m.get(me.getKey())).size() + "::" + me.getValue() + "\n");
}
}
}