39 lines
663 B
Java
39 lines
663 B
Java
class Aufgabe {
|
|
public static void main(String[] args) {
|
|
final int START = 1;
|
|
final int ENDE = 20;
|
|
|
|
int summe = 0;
|
|
int n = 0;
|
|
|
|
System.out.println("Lösung mit for-Schleife:");
|
|
|
|
for(n = START; n <= ENDE; n++) {
|
|
summe += n;
|
|
System.out.println(summe);
|
|
}
|
|
|
|
System.out.println("Lösung mit while-Schleife:");
|
|
|
|
summe = 0;
|
|
n = START;
|
|
|
|
while(n <= 20) {
|
|
summe += n;
|
|
System.out.println(summe);
|
|
n++;
|
|
}
|
|
|
|
System.out.println("Lösung mit do-while-Schleife:");
|
|
|
|
summe = 0;
|
|
n = START;
|
|
|
|
do {
|
|
summe += n;
|
|
System.out.println(summe);
|
|
n++;
|
|
} while (n <= ENDE);
|
|
}
|
|
}
|