Conditionals
Conditionals
When writing If/Else statements in Java once again it will look fairly identical to JS:
JavaScript
let x = 4
if (x > 5) {
console.log("High")
} else {
console.log("Low")
}
Java
int x = 4;
if (x > 5) {
System.out.println("High");
} else {
System.out.println("Low");
}
Truthy/Falsy
Java however, does not have truthy/falsy. The below code will throw an error in Java:
int x = 4
if (x) {
System.out.println("High");
} else {
System.out.println("Low");
}
//result will throw an error
In Java you must declare what the condition is in order for the conditional to work properly.