**第一題:**
輸入一行字符,分別統計出其英文字母、空格、數字和其它字符的個數。
提示:
對比char字符在ASK碼的范圍,就可以確定它符號的類別
char字符ASK碼的范圍
* 數字0到9:?48~57
* 字母A到Z:65到90?a到z:97到122
* 空格是32
如:
```
char a = 'a';
97<= a <=122
```
~~~
public class Demo {
public static void main(String[] args) {
getCharNum("");
}
public static void getCharNum(String str) {
//數字字符總數
int num = 0;
//字母字符總數
int eng = 0;
//空格總數
int space = 0;
//其他字符總數
int other = 0;
if(str != null) {
//首先將string類型的字符串,變為一個個的char數組
char[] charArray = str.toCharArray();
for(int i = 0; i < charArray.length; i++) {
char c = charArray[i];
//對遍歷出來的char值做判斷
if (c >= 48 && c <= 57) {//字符是數字
num++;
} else if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) {//字符是字母
eng++;
} else if (c == 32) {//字符是空格
space++;
} else {
other++;//其他
}
}
System.out.println("數字有:" + num + "個," + "字母有:" + eng + "個," + "空格有:" + space + "個," + "其他字符有:" + other + "個");
} else {
System.out.println("輸入字符不合法");
}
}
}
~~~
**第二題**
要求寫一個秒表類(StopWatch),該秒表類該類在系統中只能有存在一個實例。并且存在star方法,可以用于開始計時,并且輸出開始時間,同時存在stop方法用于停止計時,輸出結束時間,要求秒表可以存儲以毫秒為單位十個計時任務
~~~
public class StopWatch {
private static StopWatch stopWatch = new StopWatch();
private StopWatch() {
}
public static StopWatch getInstance() {
return stopWatch;
}
private long startTime;
private List<Long> record = new ArrayList<Long>();
public List<Long> getRecord() {
return record;
}
public void start() {
Date date = new Date();
this.startTime = date.getTime();
}
public void end() {
if(startTime == 0) {
System.out.println("未曾開始");
} else {
Date date = new Date();
long endTime = date.getTime();
long time = endTime - startTime;
if(record.size() >= 10) {
record.remove(0);
record.add(time);
} else {
record.add(time);
}
this.startTime = 0;
}
}
}
public class Demo {
public static void main(String[] args) throws InterruptedException {
StopWatch stopWatch = StopWatch.getInstance();
//第一次計時
stopWatch.start();
System.out.println(stopWatch.getRecord());
//讓程序休息30毫秒
Thread.sleep(30);
stopWatch.end();
System.out.println(stopWatch.getRecord());
//第二次計時
stopWatch.start();
//讓程序休息10毫秒
Thread.sleep(10);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(3);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(4);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(5);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(6);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(7);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(8);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(9);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(10);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(11);
stopWatch.end();
System.out.println(stopWatch.getRecord());
stopWatch.start();
Thread.sleep(12);
stopWatch.end();
System.out.println(stopWatch.getRecord());
}
}
~~~
# 綜合案例(面向對象)
## 場景案例:
學校新開一門專業,叫做計算機科學與應用,專業編號J0001,學制年限為4年。
現有三名學生如下表所示,加入該專業學習,要求采用Java面向對象的思維描述該場景:
| 姓名 | 學號 | 性別 | 年齡 |
| --- | --- | --- | --- |
| 張三 | S01 | 男 | 18歲 |
| 李四 | S02 | 女 | 17歲 |
| 王五 | S03 | 男 | 18歲 |
## 實現效果

## 案例分析
1. 本場景中共存在幾個對象?各自的特征是什么?
2. 我們又可以針對這幾個對象抽象歸納出幾個類出來
## 代碼實現
- Java業余班教學管理
- JAVA基礎
- JAVA開發學習準備
- JAVA介紹
- 開發JAVA的準備
- JAVA的運行原理
- JDK配置
- 我的第一個JAVA程序
- 類與對象
- 基礎語言要素
- 數據類型
- Eclipse的安裝與使用
- 變量
- 直接量
- 運算符
- 流程控制
- 數組結構
- 面向對象
- 隱藏與封裝
- 深入構造器
- 類的繼承
- 多態
- 包裝類
- final修飾符
- 抽象類
- 接口
- 設計模式
- 單例模式
- 工廠模式
- 集合框架
- 集合排序
- 常用類學習
- 異常處理
- Java基礎綜合練習
- JAVA高級
- 泛型
- 多線程
- 線程的創建
- 線程的生命周期
- 線程同步
- 線程通信
- 輸入輸出流(I/O編程)
- File文件操作
- 字節流與字符流
- 數據庫
- 數據庫介紹
- 數據庫安裝
- SQL
- 表的基本操作
- 修改數據語句
- 數據檢索操作
- 多表數據操作
- 表結構設計
- 綜合應用
- JavaWeb