Intermediate Java
Jim White
Java Developer
If the condition is true ✅ ➡ do something
If the condition is false ❌ ➡ do nothing
If score is 90+ ➡ print "Great job!"
If score is less than 90 ➡ don't print it
if (condition) {
// Code to run
}
If the condition is true, the code inside curly brackets runs
=
, !=
, >
, <
, >=
, <=
, ... // 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!
We can have different conditions, if they evaluate to 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!");
}
Intermediate Java