Середній рівень Java
Jim White
Java Developer
Якщо умова істинна ✅ ➡ виконайте дію
Якщо умова хибна ❌ ➡ нічого не робіть
Якщо бал 90+ ➡ вивести "Great job!"
Якщо бал менший за 90 ➡ нічого не виводити
if (condition) {
// Code to run
}
Якщо умова істинна, код у фігурних дужках виконується
==, !=, >, <, >=, <=, ... // 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!
Можна мати різні умови, якщо вони обчислюються як true /false
if (score != 0){
System.out.println("Well, you got some points!");
}
if (message.equals("F")){
System.out.println("Try again!");
}
if (testResult == 100) {
System.out.println("Wow, you got it all!");
}
Середній рівень Java