Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions methods.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.HashMap;
import java.util.Map;

public class methods {
static Map init(int[] a) {
Map<Integer, Integer> counter = new HashMap<>();
for (int x: a) {
int newValue = counter.getOrDefault(x, 0) + 1;
counter.put(x, newValue);
}
return counter;
}

static void showCounter(Map<Integer, Integer> counter) {
for (Map.Entry<Integer, Integer> a : counter.entrySet()) {
System.out.printf("%d - встречается %d раз\n", a.getKey(), a.getValue());
}
}
}
6 changes: 6 additions & 0 deletions program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class program {
public static void main(String[] args) {
int[] a = new int[] {1, 3, 5, 6, 6, 6, 6, 6, 7, 3, 1, 1, 1, 1, 9};
methods.showCounter(methods.init(a));
}
}