Java trung cấp
Jim White
Java Developer
Nếu điều kiện đúng ✅ ➡ thực hiện hành động
Nếu điều kiện sai ❌ ➡ không làm gì
Nếu điểm từ 90 trở lên ➡ in "Great job!"
Nếu điểm dưới 90 ➡ không in
if (condition) {
// Code to run
}
Nếu điều kiện đúng, mã trong ngoặc nhọn sẽ chạy
==, !=, >, <, >=, <=, ... // 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!
Ta có thể có nhiều điều kiện, nếu chúng đánh giá là 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 trung cấp