1
7 public class ZiffernsummentestMethode {
8 public static void main(String[] args) {
9
10 int n = 200;
11 int z = 13;
12
13 int anzahl; int i;
16
18 anzahl = 0;
19 i = 1;
20
21 while( i <= n ) {
23
24 if ( ziffernsumme(i) == z ) {
25 System.out.println(i);
26 anzahl = anzahl + 1; }
28
29 i = i + 1;
31 }
32
33 System.out.println(anzahl);
34
35 }
36
37
40 private static int ziffernsumme(int zahl) {
41
42 int summe;
43 int ziffer;
44
45 summe = 0;
46
47 while ( zahl > 0 ) {
48
49 ziffer = zahl % 10;
50 summe = summe + ziffer;
51 zahl = zahl / 10; }
54
55 return summe;
56 }
57
58 }
59