Jika lagi Java
if (condition) {
// statement
} else if(condition){
// statement
}else{
// statement
}
CodePadding
if (condition) {
// statement
} else if(condition){
// statement
}else{
// statement
}
class IfStatement {
public static void main(String[] args) {
int number = 10;
// checks if number is less than 0
if (number < 0) {
System.out.println("The number is negative.");
}
System.out.println("Statement outside if block");
}
}
// A basic simple of an if statement
var apples = 10;
var bananas = 11;
if (apples > bananas) {
print("Too much apples")
} else {
print("Too much bananas")
}
if (condition) {
// codes in if block
}
else {
// codes in else block
}
if (condition1) {
// codes
}
else if(condition2) {
// codes
}
else if (condition3) {
// codes
}
.
.
else {
// codes
}
// Traditional way
if (20 > 18) {
System.out.println("20 is greater than 18");
}
// "efficient" way
int time = 20;
String result = (time < 18) ? "Good day." : "Good evening.";
System.out.println(result);