Java 入門
Jim White
Java Developer
true または false で評価する(結果は boolean)
class GreaterThan {
public static void main(String[] args){
System.out.println(5 < 6); // Will print true, 5 is less than 6
}
}
true
// Check if 5 is less than 6
boolean x = 5 < 6; // Value is true, because 5 < 6
// Check if 5 is greater than 6
boolean y = 5 > 6; // Value is false, 5 < 6
int minSpend = 25; int total = 25;// Check if total is greater or equal to minSpend boolean freeDelivery = total >= minSpend; // Value is true, total is equal to minSpend
int minSpend = 25;
int total = 23;
// Check if total is less or equal to minSpend
boolean paidDelivery = total <= minSpend; // Value is true, total is less than minSpend
==を使用(=は代入用)int userAccountNumber = 567346;
int submittedAccountNumber = 456777;
// Check if userAccountNumber is equal to submittedAccountNumber
boolean isUserAccountNumber = useraccountNumber == submittedAccountNumber;
// Value is false
!= を使用int userHealth = 235;
// Check whether userHealth is not zero
boolean alive = userHealth != 0; // Value is true, userHealth is not zero
| 演算子 | 名前 | 例 | 例の結果 |
|---|---|---|---|
| > | 大なり | 6 > 6 | false |
| < | 小なり | 5 < 6 | true |
| >= | 大なりイコール | 5 >= 6 | false |
| <= | 小なりイコール | 5 <=6 | true |
| == | イコール | 5 == 5 | true |
| != | ノットイコール | 5 != 5 | false |
booleanJava 入門