Hallo, ich bin gerade dabei mir eine While Schlaufe zu programmieren. Es sieht bis her so aus:
public class HalloWelt {
public static void main(String[] args) {
int a = 5;
int b = 0;
int ergebnis;
ergebnis = a + b;
while (ergebnis == 5) {
System.out.println("Ergbnis ist 5");
b++;
}
System.out.println("Ergebnis ist nicht 5");
}
}
Er soll solange das Ergebnis 5 ist "Ergebnis ist 5" ausgeben also nur einmal, da ich es durch b++; erhöhe. Dies tut es aber nicht. Es gibt immer wieder aus "Ergebnis ist 5", obwohl es einmal "Ergebnis ist 5" ausgeben soll und dann "Ergebnis ist nicht 5
public class HalloWelt {
public static void main(String[] args) {
int a = 5;
int b = 0;
int ergebnis;
ergebnis = a + b;
while (ergebnis == 5) {
System.out.println("Ergbnis ist 5");
b++;
}
System.out.println("Ergebnis ist nicht 5");
}
}
Er soll solange das Ergebnis 5 ist "Ergebnis ist 5" ausgeben also nur einmal, da ich es durch b++; erhöhe. Dies tut es aber nicht. Es gibt immer wieder aus "Ergebnis ist 5", obwohl es einmal "Ergebnis ist 5" ausgeben soll und dann "Ergebnis ist nicht 5