Java 소개
Jim White
Java Developer
true 또는 false로 평가됨(결과는 boolean)
class GreaterThan {
public static void main(String[] args){
System.out.println(5 < 6); // true 출력, 5는 6보다 작음
}
}
true
// 5가 6보다 작은지 확인
boolean x = 5 < 6; // 값은 true, 5 < 6
// 5가 6보다 큰지 확인
boolean y = 5 > 6; // 값은 false, 5 < 6
int minSpend = 25; int total = 25;// total이 minSpend 이상인지 확인 boolean freeDelivery = total >= minSpend; // 값은 true, total이 minSpend와 같음
int minSpend = 25;
int total = 23;
// total이 minSpend 이하인지 확인
boolean paidDelivery = total <= minSpend; // 값은 true, total이 minSpend보다 작음
==를 사용해야 함, =는 대입용int userAccountNumber = 567346;
int submittedAccountNumber = 456777;
// userAccountNumber가 submittedAccountNumber와 같은지 확인
boolean isUserAccountNumber = useraccountNumber == submittedAccountNumber;
// 값은 false
!= 사용int userHealth = 235;
// userHealth가 0이 아닌지 확인
boolean alive = userHealth != 0; // 값은 true, userHealth는 0이 아님
| Operator | Name | Example | Result of example |
|---|---|---|---|
| > | Greater than | 6 > 6 | false |
| < | Less than | 5 < 6 | true |
| >= | Greater or equal to | 5 >= 6 | false |
| <= | Less or equal to | 5 <=6 | true |
| == | Equal to | 5 == 5 | true |
| != | Not equal to | 5 != 5 | false |
booleanJava 소개