2022-07-15 第五小組 孔海波 學習筆記
- 2022 年 7 月 15 日
- 筆記
今日學習情況:理解
心情:70%
今天學了一天算法,心情就不說了…..
Java基礎
Java基礎
數據結構
1.數組是最基本的數據結構
2.鏈表
3.樹
4.圖(深度優先,廣度優先)
冒泡排序
public class Maopao {
public static void main(String[] args) {
int[] arr = new int[]{98, 946, 5, 3, 133, 216, 45, 1, 85, 6};
for (int i : maoSort(arr)) {
System.out.print(i + ",");
}
}
public static int[] maoSort(int[] arr) {
int tmp;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
return arr;
}
}
選擇排序
public class Selectsort {
public static void main(String[] args) {
int[] arr = new int[]{9, 8, 7, 6, 5, 4, 8, 3, 2, 1, 0};
for (int j : selectSort(arr)) {
System.out.print(j + ",");
}
}
public static int[] selectSort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int index = i, temp;
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
index = j;
}
temp = arr[index];
arr[index] = arr[i];
arr[i] = temp;
}
}
return arr;
}
}
插入排序
public class Selectsort {
public static void main(String[] args) {
int[] arr = new int[]{9, 8, 7, 6, 5, 4, 8, 3, 2, 1, 0};
for (int j : selectSort(arr)) {
System.out.print(j + ",");
}
}
public static int[] selectSort(int[] arr) {
for (int i = 0; i < arr.length; i++) {
int index = i, temp;
for (int j = i + 1; j < arr.length; j++) {
if (arr[i] > arr[j]) {
index = j;
}
temp = arr[index];
arr[index] = arr[i];
arr[i] = temp;
}
}
return arr;
}
}
員工信息管理系統
這是老師留的作業…
package work;
import java.util.Scanner;
public class ManageSystem {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[][] employeeData = new String[2][3];
//int id = 1, name = 1, hobby = 1;
int employeeNum = 0;
top:
while (true) {
System.out.println("歡迎使用員工管理系統:\n* * * * * * * * * ");
System.out.println("* 輸入數字請選擇功能\t*\n* 1:添加員工\t\t*\n* 2:查詢員工\t\t*\n* " +
" 3:修改員工\t\t*\n* 4:刪除員工 \t\t*\n* 0:退出系統 \t\t*\n* *" +
" * * * * * * *");
String flag = in.next();
switch (flag) {
case "1":
while (true) {
if (employeeNum >= employeeData.length) {
String[][] temp = new String[2 * employeeData.length][3];
for (int i = 0; i < employeeData.length; i++) {
for (int j = 0; j < 3; j++) {
temp[i][j] = employeeData[i][j];
}
}
employeeData = temp;
}
employeeData[employeeNum][0] = "Ygh" + (employeeNum + 1);
System.out.println("請輸入員工姓名:");
employeeData[employeeNum][1] = in.next();
System.out.println("請輸入員工愛好:");
employeeData[employeeNum][2] = in.next();
employeeNum++;
System.out.println("添加成功!\n是否繼續添加?(輸入 1 繼續添加,輸入 2 回到主頁面,輸入其它退出系統!)");
String temp = in.next();
if (temp.equals("1"))
continue;
else if (temp.equals("2"))
continue top;
break top;
}
case "2":
top2:
while (true) {
System.out.println("請選擇你要查詢的類型序號:\n1:通過員工號查詢\n2:查詢全部");
String temp_1 = in.next();
if (temp_1.equals("2")) {
System.out.println("工號 姓名 愛好");
for (int i = 0; i < employeeNum; i++) {
for (int j = 0; j < 3; j++) {
System.out.print(employeeData[i][j] + " ");
}
System.out.println();
}
System.out.println("查詢成功!\n是否繼續查詢?(輸入 1 繼續查詢,輸入 2 回到主頁面," +
"輸入其它退出系統!)");
String temp = in.next();
if (temp.equals("1"))
continue top2;
else if (temp.equals("2"))
continue top;
break top;
} else if (temp_1.equals("1")) {
System.out.println("請輸入你要查詢的員工號(Ygh + 序號):");
String id = in.next();
for (int i = 0; i < employeeNum; i++) {
if (id.equals(employeeData[i][0])) {
System.out.println("員工號:" + employeeData[i][0] + "\n員工姓名:" +
employeeData[i][1] + "\n員工愛好:" + employeeData[i][2]);
System.out.println("查詢成功!\n是否繼續查詢?(輸入 1 繼續查詢,輸入 2 回到主頁面," +
"輸入其它退出系統!)");
String temp = in.next();
if (temp.equals("1"))
continue top2;
else if (temp.equals("2"))
continue top;
break top;
}
}
System.out.println("沒有此員工號的員工,輸入 1 重新查詢,輸入 2 回到主頁面,輸入其它退出系統!");
String temp = in.next();
if (temp.equals("1"))
continue top2;
else if (temp.equals("2"))
continue top;
break top;
} else
System.out.println("你輸入的有誤,請重新輸入。");
}
case "3":
top3:
while (true) {
System.out.println("請輸入你要修改的員工號(Ygh + 序號):");
String id = in.next();
for (int i = 0; i < employeeNum; i++) {
if (id.equals(employeeData[i][0])) {
System.out.println("員工號:" + employeeData[i][0] + "\n員工姓名:" +
employeeData[i][1] + "\n員工愛好:" + employeeData[i][2]);
System.out.println("請輸入你要修改的姓名:");
employeeData[i][1] = in.next();
System.out.println("請輸入你要修改的愛好:");
employeeData[i][2] = in.next();
System.out.println("修改成功!\n是否繼續修改?(輸入 1 繼續修改,輸入 2 回到主頁面," +
"輸入其它退出系統!)");
String temp = in.next();
if (temp.equals("1"))
continue top3;
else if (temp.equals("2"))
continue top;
break top;
}
}
System.out.println("沒有此員工號的員工,輸入 1 繼續修改,輸入 2 回到主頁面,輸入其它退出系統!");
String temp = in.next();
if (temp.equals("2"))
continue top;
else if (temp.equals("1"))
continue top3;
break top;
}
case "4":
top4:
while (true) {
System.out.println("請輸入你要刪除的員工號(Ygh + 序號):");
String id = in.next();
for (int i = 0; i < employeeNum; i++) {
if (id.equals(employeeData[i][0])) {
System.out.println("員工號:" + employeeData[i][0] + "\n員工姓名:" +
employeeData[i][1] + "\n員工愛好:" + employeeData[i][2]);
System.out.println("確認刪除嗎(輸入」y「或者」y「刪除,輸入其他返回主頁面)?");
String temp_2 = in.next();
if (temp_2.equals("Y") || temp_2.equals("y")) {
while (i <= employeeNum - 1) {
employeeData[i][0] = employeeData[i + 1][0];
employeeData[i][1] = employeeData[i + 1][1];
employeeData[i][2] = employeeData[i + 1][2];
i++;
}
employeeNum--;
} else
continue top;
System.out.println("修改成功!\n是否繼續刪除?(輸入 1 繼續刪除,輸入 2 回到主頁面," +
"輸入其它退出系統!)");
String temp = in.next();
if (temp.equals("1"))
continue top4;
else if (temp.equals("2"))
continue top;
break top;
}
}
System.out.println("沒有此員工號的員工,輸入 1 重新輸入,輸入 2 回到主頁面,輸入其它退出系統!");
}
case "0":
break top;
default:
System.out.println("你輸入的信息錯誤,請重新輸入。");
}
}
System.out.println("謝謝使用員工管理系統,再見!!!");
}
}
我們輸入蔡徐坤信息後選擇查詢全部,顯示出全部蔡徐坤信息!完美運行。