Feladatok‎ > ‎Miből hány van?‎ > ‎

Megoldás

CountOccurrences.java:
import java.util.Scanner;

public class CountOccurrences {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt(),
m = sc.nextInt();

int[] count = new int[m]; // 0 – (m-1)-ig! Minden elem 0!

for (int i = 0; i < n; i++) {
int number = sc.nextInt();
count[number - 1]++; // Az index el van csúsztatva!
}

for (int i = 0; i < m; i++) {
System.out.println((i + 1) + ": " + count[i]); // Az index el van csúsztatva!
}

}

}
Comments