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 ระดับกลาง