Java für Fortgeschrittene
Jim White
Java Developer
Wenn die Bedingung wahr ist ✅ ➡ etwas ausführen
Wenn die Bedingung falsch ist ❌ ➡ nichts tun
Wenn score ≥ 90 ➡ "Great job!" ausgeben
Wenn score < 90 ➡ nicht ausgeben
if (condition) {
// Code to run
}
Wenn die Bedingung wahr ist, läuft der Code in den geschweiften Klammern
==, !=, >, <, >=, <=, ... // Print "Great job!" if score is >= 90
if (score >= 90) {
System.out.println("Great job!");
}
int score = 94;
if (score >= 90) {
System.out.println("Excellent!");
}
if (score >= 70) {
System.out.println("Good job!");
}
if (score < 70) {
System.out.println("Try again!");
}
Excellent!
Good job!
Wir können verschiedene Bedingungen haben, die zu true/false auswerten
if (score != 0){
System.out.println("Na, ein paar Punkte hast du!");
}
if (message.equals("F")){
System.out.println("Versuch's noch mal!");
}
if (testResult == 100) {
System.out.println("Wow, alles richtig!");
}
Java für Fortgeschrittene