日常更新

This commit is contained in:
2023-03-03 17:26:53 +08:00
parent efb6a28fcb
commit 52a7551492
17 changed files with 379 additions and 1 deletions
+79
View File
@@ -0,0 +1,79 @@
总的来说,Java的条件判断(if)与选择语法与C一致。这一章我们通过几个例子来说明Java的上述语法,同时对一些Java的特性进行讲解。
## 1. 布尔类型与布尔计算
Java的布尔类型和C保持一致,基本的运算符也和C保持一致。
**注意,布尔类型是 boolean,并有大写的布尔类型Boolean。这两个类型是不同的,小写的是基本类型(与C一致);大写的表示封装类型(类)是面向对象的类型。**
### 1.1. 关系运算
![](img/20230303170551.png)
### 1.2. 逻辑运算
![](img/20230303170617.png)
![](img/20230303170628.png)
![](img/20230303170639.png)
![](img/20230303170647.png)
![](img/20230303170657.png)
### 1.3. 位运算
### 1.4. 选择语句
### 1.5. 运算优先级
尽量使用括号
### 1.6. 补充例子
#### 1.6.1. 如何循环的读取输入
这个方式在书上没有讲,在考试中可能会遇到这种情况。
```java
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. 本页的补充例子,循环读取输入