You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
总的来说, Java的条件判断( if) 与选择语法与C一致。这一章我们通过几个例子来说明Java的上述语法, 同时对一些Java的特性进行讲解。
## 1. 布尔类型与布尔计算
Java的布尔类型和C保持一致, 基本的运算符也和C保持一致。
** 注意,布尔类型是 boolean, 并有大写的布尔类型Boolean。这两个类型是不同的, 小写的是基本类型( 与C一致) ; 大写的表示封装类型( 类) 是面向对象的类型。**
### 1.1. 关系运算

### 1.2. 逻辑运算





### 1.3. 位运算
略
### 1.4. 选择语句
略
### 1.5. 运算优先级
尽量使用括号
### 1.6. 补充例子
#### 1.6.1. 如何循环的读取输入
这个方式在书上没有讲,在考试中可能会遇到这种情况。
```java {.line-numbers}
import java.util.Scanner;
/**
* 循环读取,一直到某个特定的条件退出
*
* @author Danny
*
*/
public class LoopRead {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Please input a sequence of integer, divided by space.");
int sum = 0;
while (true) {
if (scanner.hasNextInt()) {
sum += scanner.nextInt();
} else {
break;
}
}
scanner.close();
System.out.println("The sum is: " + sum);
}
}
```
## 2. 重点
本章的内容中的大部分技术要点都与C保持一致, 因此之需要掌握几个例子就可以了:
1. AdditionQuiz
2. SubtractionQuiz
3. ComputeAndInterpretBMI
4. ComputeTax
5. ChineseZodiac
6. 本页的补充例子,循环读取输入