-
Notifications
You must be signed in to change notification settings - Fork 0
/
Histogram.java
38 lines (35 loc) · 1.16 KB
/
Histogram.java
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
package pololetni_prace;
public class Histogram {
public static void main(String[] args) {
Zaznam[] cetnosti = new Zaznam[500];
int pocet = 0;
java.util.Scanner scanner = new java.util.Scanner(System.in);
while (scanner.hasNextInt()) {
int cislo = scanner.nextInt();
boolean nasel = false;
for (int i = 0; i < pocet; i++) {
if (cetnosti[i].cislo == cislo) {
cetnosti[i].pocet++;
nasel = true;
break;
}
}
if (!nasel) {
if (pocet < cetnosti.length) {
cetnosti[pocet] = new Zaznam(cislo);
pocet++;
} else {
System.out.printf("Preskakuji %d!\n", cislo);
}
}
}
for (int i = 0; i < pocet; i++) {
System.out.printf("%3d", cetnosti[i].cislo);
System.out.printf("%3d", cetnosti[i].pocet);
for (int a = 0; a < cetnosti[i].pocet; a++) {
System.out.print("#");
}
System.out.print("\n");
}
}
}