Introductie tot Java
Jim White
Java Developer
true of false (resultaat is een boolean)
class GreaterThan {
public static void main(String[] args){
System.out.println(5 < 6); // Print true, 5 is kleiner dan 6
}
}
true
// Check of 5 kleiner is dan 6
boolean x = 5 < 6; // Waarde is true, want 5 < 6
// Check of 5 groter is dan 6
boolean y = 5 > 6; // Waarde is false, 5 < 6
int minSpend = 25; int total = 25;// Check of total groter of gelijk is aan minSpend boolean freeDelivery = total >= minSpend; // Waarde is true, total is gelijk aan minSpend
int minSpend = 25;
int total = 23;
// Check if total less of gelijk is aan minSpend
boolean paidDelivery = total <= minSpend; // Waarde is true, total is kleiner dan minSpend
==, = is voor toewijzingint userAccountNumber = 567346;
int submittedAccountNumber = 456777;
// Check of userAccountNumber gelijk is aan submittedAccountNumber
boolean isUserAccountNumber = useraccountNumber == submittedAccountNumber;
// Waarde is false
!=int userHealth = 235;
// Check of userHealth niet nul is
boolean alive = userHealth != 0; // Waarde is true, userHealth is niet nul
| Operator | Naam | Voorbeeld | Resultaat voorbeeld |
|---|---|---|---|
| > | Groter dan | 6 > 6 | false |
| < | Kleiner dan | 5 < 6 | true |
| >= | Groter of gelijk | 5 >= 6 | false |
| <= | Kleiner of gelijk | 5 <=6 | true |
| == | Gelijk aan | 5 == 5 | true |
| != | Niet gelijk aan | 5 != 5 | false |
booleanIntroductie tot Java