diff --git "a/11 \345\276\220\347\253\213\345\237\216/20221202 if\350\257\255\345\217\245.md" "b/11 \345\276\220\347\253\213\345\237\216/20221202 if\350\257\255\345\217\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..7e3eca00ff52bf17e11299251f7f5b34d65d15e6 --- /dev/null +++ "b/11 \345\276\220\347\253\213\345\237\216/20221202 if\350\257\255\345\217\245.md" @@ -0,0 +1,335 @@ +## 笔记 + +#### 分支结构之if语句 + +```java +格式: +if (关系表达式) { + 语句体; +} +``` + +执行流程: + +①首先计算关系表达式的值 + +②如果关系表达式的值为true就执行语句体 + +③如果关系表达式的值为false就不执行语句体 + +④继续执行后面的语句内容 + +示例: + +```java +public class IfDemo { +public static void main(String[] args) { +System.out.println("开始"); +// 如果年龄大于18岁, 就可以上网吧 +int age = 17; +if(age >= 18){ +// int a = 10; +System.out.println("可以上网吧"); +} +System.out.println("结束"); +} +} + +``` + +#### 3.3.2 if语句格式2(理解) + +```java +格式: +if (关系表达式) { +语句体1; +} else { +语句体2; +} + +``` + +执行流程: + +①首先计算关系表达式的值 + +②如果关系表达式的值为true就执行语句体1 + +③如果关系表达式的值为false就执行语句体2 + +④继续执行后面的语句内容 + +#### 3.3.3 if语句格式3(理解) + +```java +格式: +if (关系表达式1) { +语句体1; +} else if (关系表达式2) { +语句体2; +} +… +else { +语句体n+1; +} + +``` + +执行流程: + +①首先计算关系表达式1的值 + +②如果值为true就执行语句体1;如果值为false就计算关系表达式2的值 + +③如果值为true就执行语句体2;如果值为false就计算关系表达式3的值 + +④… + +⑤如果没有任何关系表达式为true,就执行语句体n+1。 + +## 分支语句switch语句 + +格式 + +```java +switch (表达式) { + case 1: + 语句体1; + break; + case 2: + 语句体2; + break; + ... + default: + 语句体n+1; + break; +} +``` + +执行流程: + +首先计算出表达式的值 + +其次,和case依次比较,一旦有对应的值,就会执行相应的语句,在执行的过程中,遇到 break就会结 束。 + +最后,如果所有的case都和表达式的值不匹配,就会执行default语句体部分,然后程序结束 掉。 + +#### switch语句case穿透 + +概述 : 如果switch语句中,case省略了break语句, 就会开始case穿透 + +需求 : 键盘录入星期数,输出工作日、休息日 (1-5)工作日,(6-7)休息日 + +示例代码: + +```java +/* +case穿透是如何产生的? +如果switch语句中,case省略了break语句, 就会开始case穿透. +现象: +当开始case穿透,后续的case就不会具有匹配效果,内部的语句都会执行 +直到看见break,或者将整体switch语句执行完毕,才会结束。 +*/ +public static void main(String[] args){ + Scanner sc = new Scanner(System.in); + System.out.println("请输入星期数:"); + int week = sc.nextInt(); + + switch(week){ + case 1: + case 2: + case 3: + case 4: + case 5: + System.out.println("工作日"); + break; + case 6: + case 7: + System.out.println("休息日"); +break; +``` + + + +### 作业1 + +``` Java +import java.util.Scanner; + +public class baodu { + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + System.out.println("请输入你选择的车型: 1.夏利 2.富康 3.桑塔纳"); + int n = sc.nextInt(); + switch (n) { + case 1: + System.out.println("夏利起步三元,超过三公里后每公里收2.1/千米,请输入你的公里数"); + int gl = sc.nextInt(); + if (gl<0){ + System.out.println("请重新输入你的公里数"); + } + else if (gl>3){ + double cf=3+2.1*(gl-3); + System.out.println("一共:"+cf); + }else { + double cf=3; + System.out.println("一共:"+cf); + } + break; + case 2: + System.out.println("富康起步四元,超过三公里后每公里收2.4/千米,请输入你的公里数"); + int qm = sc.nextInt(); + if (qm<0){ + System.out.println("请重新输入你的公里数"); + } + else if (qm>3){ + double cf=4+2.4*(qm-3); + System.out.println("一共:"+cf); + }else { + double cf=4; + System.out.println("一共:"+cf); + } + break; + default: + System.out.println("桑塔纳起步四元,超过三公里后每公里收2.4/千米,请输入你的公里数"); + int kk = sc.nextInt(); + if (kk<0){ + System.out.println("请重新输入你的公里数"); + } + else if (kk>3){ + double cf=5+2.7*(kk-3); + System.out.println("一共:"+cf); + }else { + double cf=5; + System.out.println("一共:"+cf); + } + break; + } + + } +} +``` + +### 作业2 + +```java +import java.util.Scanner; + +public class lx { + public static void main(String[] args) { + System.out.println("请输入年"); + Scanner kk = new Scanner(System.in); + int a = kk.nextInt(); + if (a > 2022 && a < 0) { + System.out.println("请输入正确的年份"); + + System.out.println("请输入月份"); + Scanner sc = new Scanner(System.in); + char b = sc.next().charAt(0); + System.out.println("请输入日"); + Scanner zz = new Scanner(System.in); + int c = zz.nextInt(); + int p=28; + if (b >= 3 && a % 4 == 0 && a % 100 != 0) + { + p= p+1; + } + int l = 0; + if (b >= 0 && b <= 12) { + + switch (b) { + case 1: + l = c; + break; + case 2: + l = c + 31; + break; + case 3: + l = c + 31 + p; + break; + case 4: + l = c + 31 + p + 31; + break; + case 5: + l = c + 31 * 2 + p + 30; + break; + case 6: + l = c + 31 * 3 + p + 30; + break; + case 7: + l = c + 31 * 3 + p + 30 * 2; + break; + case 8: + l = c + 31 * 4 + p + 30 * 2; + break; + case 9: + l = c + 31 * 5 + p + 30 * 2; + break; + case 10: + l = c + 31 * 5 + p + 30 * 3; + break; + case 11: + l = c + 31 * 6 + p + 30 * 3; + break; + case 12: + l = c + 31 * 6 + p + 30 * 4; + break; + } + + } + System.out.println(a+"年"+b+"月"+c+"日一共:"+l); + } + } + } +``` + +### 作业3 + +```java +import java.util.Scanner; + +public class kk { + public static void main(String[] args) { + System.out.println("请输入一个字符:"); + Scanner sc = new Scanner(System.in); + char a = sc.next().charAt(0); + if (a>=65 && a<=90){ + System.out.println("大写字母"); + + switch (a){ + case 'A': + case 'E': + case 'I': + case 'O': + case 'U': + case 'V': + System.out.println("是韵母"); + break; + default: + System.out.println( "是声母"); + } + } else if (a>=97 && a<=122) { + System.out.println("小写字母"); + switch (a){ + case 'a': + case 'e': + case 'i': + case 'o': + case 'u': + case 'v': + System.out.println("是韵母"); + break; + default: + System.out.println( "是声母"); + } + } + else { + System.out.println("请输入字母"); + } + } + + +} + +``` \ No newline at end of file diff --git "a/11 \345\276\220\347\253\213\345\237\216/20221206 \345\276\252\347\216\257\350\257\255\345\217\245.md" "b/11 \345\276\220\347\253\213\345\237\216/20221206 \345\276\252\347\216\257\350\257\255\345\217\245.md" new file mode 100644 index 0000000000000000000000000000000000000000..6f2019e9fe227a753a0c0faf89add1da378d03a3 --- /dev/null +++ "b/11 \345\276\220\347\253\213\345\237\216/20221206 \345\276\252\347\216\257\350\257\255\345\217\245.md" @@ -0,0 +1,144 @@ +## for循环 + +循环: + + 循环语句可以在满足循环条件的情况下,反复执行某一段代码,这段被重复执行的代码被称为循环 体语句,当反复 执行这个循环体时,需要在合适的时候把循环判断条件修改为false,从而结束循 环,否则循环将一直执行下去,形 成死循环。 + + for循环格式: + +```java +for +(初始化语句;条件判断语句;条件控制语句) { +循环体语句; +} +``` + +格式解释: + +初始化语句: 用于表示循环开启时的起始状态,简单说就是循环开始的时候什么样 + +条件判断语句:用于表示循环反复执行的条件,简单说就是判断循环是否能一直执行下去 + +循环体语句: 用于表示循环反复执行的内容,简单说就是循环反复执行的事情 + +条件控制语句:用于表示循环执行中每次变化的内容,简单说就是控制循环是否能执行下去 + +执行流程: ①执行初始化语句 + +②执行条件判断语句,看其结果是true还是false + +如果是false,循环结束 如果是true,继续执行 + +③执行循环体语句 + +④执行条件控制语句 + +⑤回到②继续 + +## for循环案例-水仙花数 + +需求:在控制台输出所有的“水仙花数” + +解释:什么是水仙花数? + +水仙花数,指的是一个三位数,个位、十位、百位的数字立方和等于原数 例如 153 3*3*3 + 5*5*5 + 1*1*1 = 153 + +思路: + +1. 获取所有的三位数,准备进行筛选,最小的三位数为100,最大的三位数为999,使用for循环 获取 +2. 获取每一个三位数的个位,十位,百位,做if语句判断是否是水仙花数 示例代码 + +```java +public class Demo6For { +/* +需求:在控制台输出所有的“水仙花数”,要求每行打印2个 +System.out.print (打印内容); 打印后不换行 +本题要点: +今后如果需求带有统计xxx,请先想到计数器变量 +计数器变量定义的位置,必须在循环外部 +3. while循环 +3.1 循环语句-while循环 +while循环完整格式: +while循环执行流程: +①执行初始化语句 +②执行条件判断语句,看其结果是true还是false + 如果是false,循环结束 + 如果是true,继续执行 +System.out.println(打印内容); 打印后换行 +分析: +1. 定义变量count,用于保存“打印过”的数量,初始值为0 +2. 在判定和打印水仙花数的过程中,拼接空格, 但不换行,并在打印后让count变量 ++1,记录打印过的数量 +3. 在每一次count变量+1后,判断是否到达了2的倍数,是的话,换行。 +*/ +public static void main(String[] args){ +// 1. 定义变量count,用于保存“打印过”的数量,初始值为0 + int count = 0; +for(int i = 100; i <= 999; i++){ + int ge = i % 10; + int shi = i / 10 % 10; + int bai = i / 10 / 10 % 10; + if( (ge*ge*ge + shi*shi*shi + bai*bai*bai) == i){ +// 2. 在判定和打印水仙花数的过程中,拼接空格, 但不换行,并在打印后让 + count变量+1,记录打印过的数量 + System.out.print(i + " "); + count++; +// 3. 在每一次count变量+1后,判断是否到达了2的倍数,是的话,换行 + if(count % 2 == 0){ + System.out.println(); + } + } + } + } +} + +``` + +## 循环语句-dowhile循环 + +完整格式: + +```java +初始化语句; +do { +循环体语句; +条件控制语句; +}while(条件判断语句); + +``` + +执行流程: + +① 执行初始化语句 + + ② 执行循环体语句 + + ③ 执行条件控制语句 + + ④ 执行条件判断语句,看其结果是true还是false 如果是false,循环结束 如果是true,继续执行 + + ⑤ 回到②继续 + +## 示例代码: + +```java +public class DoWhileDemo { + public static void main(String[] args) { + //需求:在控制台输出5次"HelloWorld" + //for循环实现 + for(int i=1; i<=5; i++) { +System.out.println("HelloWorld"); +} +System.out.println("--------"); + //do...while循环实现 + int j = 1; + do { + System.out.println("HelloWorld"); + j++; + }while(j<=5); + } +} + +``` + + diff --git "a/11 \345\276\220\347\253\213\345\237\216/20221208 \351\232\217\346\234\272\345\207\275\346\225\260\345\222\214\345\207\275\346\225\260\347\273\204.md" "b/11 \345\276\220\347\253\213\345\237\216/20221208 \351\232\217\346\234\272\345\207\275\346\225\260\345\222\214\345\207\275\346\225\260\347\273\204.md" new file mode 100644 index 0000000000000000000000000000000000000000..626abaf757250098de04bd06b29c80c99d5b24ef --- /dev/null +++ "b/11 \345\276\220\347\253\213\345\237\216/20221208 \351\232\217\346\234\272\345\207\275\346\225\260\345\222\214\345\207\275\346\225\260\347\273\204.md" @@ -0,0 +1,233 @@ +# 1 Rando产生随机数 + +概述: +Random类似Scanner,也是Java提供好的API,内部提供了产生随机数的功能 API后续课程详细讲解,现在可以简单理解为Java已经写好的代码 + +步骤: + +1. 导入包 + import java.util.Random; + +2. 创建对象 +Random r = new Random(); +3. 产生随机数 +int num = r.nextInt(10); +解释: 10代表的是一个范围,如果括号写10,产生的随机数就是0-9,括号写20,参数的随 +机数则是0-19 + +示例 + +1. ```Java + import java.util.Random; + public class Demo1Random { + + public static void main(String[] args){ + Random r = new Random(); + for(int i = 1; i <= 10; i++){ + int num = r.nextInt(10) + 1; + System.out.println(num); + } + } + } + ``` + + 猜数字游戏(作业) + + ```java + import java.util.Random; + import java.util.Scanner; + + public class a { + public static void main(String[] args){ + + Random r = new Random(); Scanner sc = new Scanner(System.in); + int randomNum = r.nextInt(100) + 1; + int count=0; + one:while (true) { + System.out.println("请输入您猜的数据:"); + int num = sc.nextInt(); + if (num > randomNum) { + System.out.println("猜大了"); + } else if (num < randomNum) { + System.out.println("猜小了"); + } else { + System.out.println("恭喜,猜中了"); + break ; + } + count++; + if (count == 3) { + System.out.println("已经猜错三次了是否继续(输入y继续,输入其它退出)"); + char a = sc.next().charAt(0); + switch (a) { + case 'y': + case 'Y': + count -= 3; + break; + default:{ break one; + } + } + } + } + } + } + + ``` + + # 2数组 + + 1定义:数组就是存储数据长度固定的容器,存储多个数据的数据类型要一致。 + +​ 2格式 + +​ 2.1数据类型[] 数组名 + +例示: + +```java +int[] arr; +double[] arr; +char[] arr; +``` + +​ 2.2数据类型 数组名 [] + +例示: + +```Java +int arr[]; +double arr[]; +char arr[]; +``` + +​ 3数组的动态初始化 + +1定义: 数组动态初始化就是只给定数组的长度,由系统给出默认初始化值 + + 2格式 + +```java +数据类型[] 数组名 = new 数据类型[数组长度]; +``` + +例如: + +```java +int[] arr = new int[3]; +``` + +#### 1.3.3 动态初始化格式详解 + +- 等号左边: + + - int:数组的数据类型 + + - []:代表这是一个数组 + + - arr:代表数组的名称 + +- 等号右边: + + - new:为数组开辟内存空间 + - int:数组的数据类型 + - []:代表这是一个数组 + - 5:代表数组的长度 + +**代码 :** + +```java +package com.itheima.array; + +public class Demo2Array { + /* + 数组的动态初始化: + 在初始化的时候, 需要手动指定数组的长度, 系统会为数组容器分配初始值. + + 动态初始化格式: + 数据类型[] 数组名 = new 数据类型[数组的长度]; + + 注意: + 打印数组变量的时候, 会打印出数组的内存地址 + + [I@10f87f48 : + + @ : 分隔符 + [ : 当前的空间是一个数组类型 + I : 当前数组容器中所存储的数据类型 + 10f87f48 : 十六进制内存地址 + + 0 1 2 3 4 5 6 7 8 9 a b c d e f + */ + public static void main(String[] args) { + // 数据类型[] 数组名 = new 数据类型[数组的长度]; + // 通过new关键字创建了一个int类型的数组容器, 该容器可以存储5个int类型的整数, 该容器被arr数组变量所记录 + int[] arr = new int[5]; + // [I@10f87f48 + System.out.println(arr); + + byte[] bArr = new byte[3]; + // [B@b4c966a + System.out.println(bArr); + + } +} +``` + +# 数组元素访问 + +1什么是索引 + +​ 每一个存储到数组的元素,都会自动的拥有一个编号,从0开始。 + +​ 这个自动编号称为数组索引(index),可以通过数组的索引访问到数组中的元素。 + +2格式访问数组元素格式: + +```java +数组名[索引]; +``` + +例示: + +```java +package com.itheima.array; + +public class Demo3ArrayIndex { + public static void main(String[] args) { + int[] arr = new int[3]; + System.out.println(arr); + System.out.println(arr[0]); + System.out.println(arr[1]); + System.out.println(arr[2]); + + System.out.println("--------------"); + + + arr[0] = 11; + arr[1] = 22; + arr[2] = 33; + + System.out.println(arr[0]); + System.out.println(arr[1]); + System.out.println(arr[2]); + } +} +``` + +作业1 + +```java +import java.util.Scanner; +public class D8 { + public static void main(String[] args){ + int[] age =new int[10]; + Scanner sc= new Scanner(System.in); + int sun=0; + int max=0; + int mia=0; + for(int i=0; i= b) { + System.out.println("最大值为:" + a); + } else { + System.out.println("最大值为" + b); + } + } + public static int maxf(int a, int b){//有返回值 + return a>b?a:b; + } +} +``` + +2 在主函数中从键盘接收X, Y , Z 3个数,编写函数计算这3个数的立方和并返回计算结果:S=X3+Y3+Z3 + +```java +import java.util.Scanner; + +public class lfsf { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("请输入X"); + int a= sc.nextInt(); + System.out.println("请输入Y"); + int b= sc.nextInt(); + System.out.println("请输入Z"); + int c= sc.nextInt(); + int d=shuangfa(a,b,c); + System.out.println("S"+"="+"X3+Y3+Z3="+d); + } + public static int shuangfa(int a,int b,int c){ + return a*a*a+b*b*b+c*c*c; + } +} +``` + diff --git "a/11 \345\276\220\347\253\213\345\237\216/20221216 \345\207\275\346\225\260\345\244\215\344\271\240\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" "b/11 \345\276\220\347\253\213\345\237\216/20221216 \345\207\275\346\225\260\345\244\215\344\271\240\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..57a1f2149a2068f32160b2cb82cc8e481667d870 --- /dev/null +++ "b/11 \345\276\220\347\253\213\345\237\216/20221216 \345\207\275\346\225\260\345\244\215\344\271\240\347\254\224\350\256\260\345\217\212\344\275\234\344\270\232.md" @@ -0,0 +1,207 @@ +方法的注意事项: + +1格式 + +完整版: + +```java +public static 返回值类型 方法名 ( ) { + // 方法体; + return 返回值; + } + +``` + +​ 1方法前后返回值单位要一致。 + +​ 2方法体为执行语句。 + +2重载: + +定义:方法的重载是指在一个类中的多个方法,方法名相同,参数类型不同。 + +注意:返回类型、修饰符可以相同,也可不同。要求同名的方法必须有不同的参数表,仅有返回类型不同是不足以区分两个重载的方法。 + +3参数 + +1形式参数:就是方法名后面的小括号里设定的代数如 + +```java +public static viod p1(int a) { + +} +``` + +2实际参数:使用方法时在方法名后面小括号里面的值,如: + +```java +public static viod p1(3); +``` + +4数据类型: + +数据类型分为基本数据类型和引用数据类型 + +1基本数据类型:能被计算器直接读取并可以直接参与计算,如:int a = 10; + +2 引用数据类型:指数据所存放的地址,需要知道具体数据位置并需要提取计算器才能使用的数据,如:数组 + +作业 + +1编写函数,计算圆的面积和周长,在主函数中接受圆的半径,在自定义函数中计算并输出 + +```java +import java.util.Scanner; + +public class circle { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double r= sc.nextDouble(); + Circle(r); + } + public static void Circle(double r) { + double l=2*3.14*r; + double s=3.14*r*r; + System.out.println("该半径为"+r+"的圆的周长为"+l+"面积为"+s); + return; + } +} +``` + +2在主函数中产生20个0-10之间的随机数,将这20个随机数存入数组,并通过函数计算某个数在这些随机数中出现的次数(这“某个数”是在主函数中由用户输入的) + +```java +import java.util.Random; +import java.util.Scanner; + +public class repetition { + public static void main(String[] args) { + System.out.println("请输入一个0-10的整数"); + Scanner sc =new Scanner(System.in); + int n = sc.nextInt(); + if(n>10|n<0) { + System.out.println("无效数字"); + } + else { + re(n); + } + } + public static void re(int n) { + int c=0; + Random ran =new Random(); + int[] num = new int[20]; + for (int i=0;i< num.length;i++){ + num[i] = ran.nextInt(11); + if (n==num[i]){ + c++; + } + } + System.out.println("您输入的数字"+n+"在这次随机在 0-10 抽取20个数中一共重复"+c+"次");} +} + +``` + +3 在主函数中接收10个数存入数组,在自定义函数中,将该数组中的最大值与第一个元素交换,最小值与最后一个元素交换,然后在主函数中输出交换后的数组 + +```java +mport java.util.Arrays; +import java.util.Scanner; + +public class jiaohuan { + public static void main(String[] args) { + Jh(); + } + public static void Jh() { + System.out.println("请输入十个整数"); + Scanner sc = new Scanner(System.in); + int[] Main = new int[10]; + //用户输入数组循环 + for (int i = 0; i < Main.length; i++) { + int a = sc.nextInt(); + Main[i] = a; + } + int max = Main[0]; + int min = Main[0]; + int remax =Main[0];//记入开头便于交换 + int remin =Main[9];//记入结尾便于交换 + for (int am = 0; am < Main.length; am++) { + if (max < Main[am]) { + max = Main[am]; + } + } + for (int in = 0; in < Main.length; in++) { + if (min > Main[in]) { + min = Main[in]; + } + } + int cmax=0; + //获取最大值的所在位置 + max:for (int i=0;i< Main.length;i++) { + if (max == Main[i]) { + cmax += i; + break max; + } + } + int cmin=0; + //获取最小值的所在位置 + min:for (int j=0;j< Main.length;j++) { + if (min == Main[j]) { + cmin += j; + break min; + } + } + Main[0]=max;Main[cmax]=remax;//最大值交换 + Main[9]=min;Main[cmin]=remin; + System.out.println(Arrays.toString(Main)); + } +} +``` + +4用自定义函数是实现求某数组元素的和(大小不固定) + +```java +import java.util.Scanner; + +public class Sum { + public static void main(String[] args) { + sum(); + } + public static void sum(){ + Scanner sc = new Scanner(System.in); + int[] a=new int[5]; + int sum=0; + for (int i = 0; i< a.length;i++){ + a[i]= sc.nextInt(); + sum+=a[i]; + } + System.out.println("该数组数据和为"+sum); + } +} + +``` + +5用户输入整数n,计算1!+(1!+2!)+(1!+2!+3!)+…..+(1!+2!+…n!) + +```java +import java.util.Scanner; + +public class jiecheng { + public static void main(String[] args) { + Jc(); + } + public static void Jc(){ + Scanner sc=new Scanner(System.in); + int n= sc.nextInt(); + long sum=0;long num; + for (int i=1;i<=n;i++){ + num=1; + for (int j=1;j<=i;j++){ + num=num*j; + sum+=num; + } + } + System.out.println(sum); + } +} +``` + diff --git "a/11 \345\276\220\347\253\213\345\237\216/20221221 \344\275\234\344\270\232.md" "b/11 \345\276\220\347\253\213\345\237\216/20221221 \344\275\234\344\270\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..815874a9c7dd9b200d047376a4be8492107504a2 --- /dev/null +++ "b/11 \345\276\220\347\253\213\345\237\216/20221221 \344\275\234\344\270\232.md" @@ -0,0 +1,122 @@ +# 作业 + +```java +import com.sun.org.apache.xml.internal.resolver.helpers.PublicId; + +import java.security.PublicKey; +import java.util.Scanner; + +public class Main { + static Scanner sc = new Scanner(System.in); + public static void main(String[] args) { + String[] students=new String[10]; + students[0]="aa"; + students[1]="bb"; + welCome(); + while (true){caidan(sc.nextByte(),students); + } + + } + + public static void welCome() { + System.out.println("============================" + + "\n- 欢迎使用学生管理系统 - " + + "\n- \t\t1.浏览所以学生信息\t\t-" + + "\n- \t\t2.添加学生信息\t\t-" + + "\n- \t\t3.修改学生信息\t\t-" + + "\n- \t\t4.删除学生信息\t\t-" + + "\n- \t\t5.查询学生信息\t\t-" + + "\n- \t\t6.退出管理系统\t\t-" + + " \n============================" + + "\n 请输入对应的数学选择你需要的功能:" + ); + } + public static void caidan(int num,String[] stu) { + + switch (num) { + case 1: + xuesheng(stu); + break; + case 2: + add(stu); + break; + case 3: + break; + case 4: + break; + case 5: + break; + case 6: + break; + default: + System.out.println("选项错误!"); + } + + } + public static void xuesheng(String[] stu) { + System.out.println("学生有以下:"); + for (String name : stu) { + if (name == null){ + continue; + } + System.out.print(name+"\t"); + } + + } + public static void add(String[] stu) { + System.out.println("输入你添加的学生"); + String name=sc.next(); + int index=llkkd(stu,name); + if (index!=-1){ + System.out.println("该学生已存在"); + }else { + + + int nullIndex = llkkd(stu, null); + stu[nullIndex]=name; + System.out.println("添加成功"); + } + } + public static int llkkd(String[] stu,String str) { + int index = -1; + if (str == null) { + for (int i = 0; i < stu.length; i++) { + if (stu[i] == null) { + index = i; + break; + } + } + } else { + for (int i = 0; i < stu.length; i++) { + if (str.equals(stu[i])) { + index = i; + return index; + } + } + } + return index; + } +public static void xiugai(String[] stu) { + System.out.println("输入你修改的学生"); + String name=sc.next(); +for (int i=0;i< stu.length;i++) + if (name == stu[i]){ + System.out.println("请输入你要修改的信息"); + Scanner kk =new Scanner(System.in); + String nbme= kk.next(); + stu[i]=nbme; + break; + }else { + System.out.println("输入错误,请重新输入"); + break; + } + + +没写完 + + + + } +} +``` +