Jinhai‘s JAVA cheat sheet
Codecademy学习笔记 Part II
布尔操作符boolean operators
比较,等价,布尔操作符都可以用在控制流中
- &&: and
- ||: or
- ! : not
比较,等价,布尔操作符都可以用在控制流中
int shoeSize = 10;
if (shoeSize > 12) {
System.out.println("Sorry, your shoe size is currently not in stock.");
} else if (shoeSize >= 6) {
System.out.println("Your shoe size is in stock!");
} else {
System.out.println("Sorry, this store does not carry shoes smaller than a size 6.");
}
三元表达式ternary expressionint pointsScored = 21; char gameResult = (pointsScored > 20) ? 'W' : 'L'; System.out.println(gameResult);条件语句conditional statements
int restaurantRating = 3;
switch (restaurantRating) {
case 1: System.out.println("This restaurant is not my favorite.");
break;
case 2: System.out.println("This restaurant is good.");
break;
case 3: System.out.println("This restaurant is fantastic!");
break;
default: System.out.println("I've never dined at this restaurant.");
break;
}
No comments:
Post a Comment