diff --git "a/51 \347\250\213\350\210\234/20221208 \351\232\217\346\234\272\346\225\260\345\222\214\345\234\250\346\216\247\345\210\266\345\217\260\350\276\223\345\207\272\351\232\217\346\234\272\346\225\260\345\222\214\347\254\224\350\256\260.md" "b/51 \347\250\213\350\210\234/20221208 \351\232\217\346\234\272\346\225\260\345\222\214\345\234\250\346\216\247\345\210\266\345\217\260\350\276\223\345\207\272\351\232\217\346\234\272\346\225\260\345\222\214\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..f7c4e249b727d3d72cddf0bd0ea833dad0d73418 --- /dev/null +++ "b/51 \347\250\213\350\210\234/20221208 \351\232\217\346\234\272\346\225\260\345\222\214\345\234\250\346\216\247\345\210\266\345\217\260\350\276\223\345\207\272\351\232\217\346\234\272\346\225\260\345\222\214\347\254\224\350\256\260.md" @@ -0,0 +1,82 @@ +### 笔记 + +数组(array):是一种用于存储多个相同数据类型的存储模型(可以理解为容器) + 数组的定义格式: +格式1:数据类型[] 变量名; +范例: int[] arr; +定义了一个int类型的数组,数组名是arr + +格式2:数据类型 变量名[]; +范例: int arr[]; +定义了一个int类型的变量,变量名是arr数组 + + +数组的元素访问: + +推荐使用:格式1 int[] arr; +数组变量访问方式 +格式:数组名 + +数组内部保存的数据的访问方式 +格式:数组名[索引] + +索引是数组中数据的编号方式 +作用:索引用于访问数组中的数据使用,数组名[索引]等同于变量名,是一种特殊的变量名 +特征①:索引从0开始 +特征②:索引是连续的 +特征③:索引逐一增加,每次加1 + +元素打乱: + +把数组中的元素随机交换位置,每次运行都可能产生不一样的结果 +比如:arr = {12, 45, 98, 73, 60}; +遍历: +正常情况下:12,45,98,73,60 +元素打乱后:45,73,12,60,98 + +涉及到的操作 +获取数组中元素的随机索引 +Random r = new Random(); +int index = r.nextInt(arr.length); +数组中元素交换 + +### 作业 + +```java +import java.util.Random; + +public class k5 { + + public static void main(String[] args) { + int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + Random r = new Random(); + for (int i = 0; i < arr.length; i++) { + int randomIndex = r.nextInt(arr.length); + int temp = arr[i]; + arr[i] = arr[randomIndex]; + arr[randomIndex] = temp; + } + for (int i = 0; i < arr.length; i++) { + System.out.print(arr[i] + " "); + } + } +} +``` + +```java +import java.util.Scanner; + +public class k6 { + public static void main(String[] args) { + System.out.println("输入五个整数"); + Scanner str = new Scanner(System.in); + String a = str.nextLine(); + String [] b=new String[1]; + b[0]=a; + for (int i=0;i< b.length;i++){ + System.err.println(b[i]); + } + } +} +``` + diff --git "a/51 \347\250\213\350\210\234/20221212 \350\257\204\345\247\224\346\211\223\345\210\206.md" "b/51 \347\250\213\350\210\234/20221212 \350\257\204\345\247\224\346\211\223\345\210\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..c2cf1a1b1924f401ea8e1154ad03c4a405276bf5 --- /dev/null +++ "b/51 \347\250\213\350\210\234/20221212 \350\257\204\345\247\224\346\211\223\345\210\206.md" @@ -0,0 +1,60 @@ +### 笔记 + +1. 数组其实也是一个变量,可以存入多个或一个相同数据类型的数据. +2. 每个数据,称为 数组的元素 +3. 通过索引可以访问到元素的值 +4. 索引从0开始,到数组长度-1结束 +5. 通过数组名.length 得到数组的长度 +6. 有两种方式初始化数组: 初始化就是分配长度和初始值[就是赋值] + +### 作业 + +~~~java +import java.util.Scanner; +//评委打分 +public class m1 { + public static void main(String[] args) { +// 1.定义一个数组,用动态初始化完成数组元素的初始化,长度为6 + int[] arr = new int[6]; +// 2.键盘录入评委分数 + Scanner sc = new Scanner(System.in); +// 3.由于是6个评委打分,所以,接收评委分数的操作,用循环 + for (int i = 0; i < arr.length; i++) { + System.out.println("请输入第" + (i+1) + "个评委的打分:"); + int score = sc.nextInt(); + if(score >= 0 && score <= 100){ +// 合法的分值 + arr[i] = score; + }else{ +// 非法的分值 + System.out.println("您的打分输入有误, 请检查是否是0-100之间 的"); + i--; + } + } +// 4.求出数组最大值 + int max = arr[0]; + for (int i = 1; i < arr.length; i++) { + if(max < arr[i]){ + max = arr[i]; + } + } +// 5.求出数组最小值 + int min = arr[0]; + for (int i = 1; i < arr.length; i++) { + if(min > arr[i]){ + min = arr[i]; + } + } +// 6.求出数组总和 + int sum = 0; + for (int i = 0; i < arr.length; i++) { + sum += arr[i]; + } +// 7.按照计算规则进行计算得到平均分 + int avg = (sum - max - min ) / 4; +// 8.输出平均分 + System.out.println(avg); + } + } +~~~ + diff --git "a/51 \347\250\213\350\210\234/20221215 \347\205\244\346\260\224\344\270\216\344\271\230\346\263\225\350\241\250.md" "b/51 \347\250\213\350\210\234/20221215 \347\205\244\346\260\224\344\270\216\344\271\230\346\263\225\350\241\250.md" new file mode 100644 index 0000000000000000000000000000000000000000..d4e27305bf8abb0a978d130b20ce4ef4622ad586 --- /dev/null +++ "b/51 \347\250\213\350\210\234/20221215 \347\205\244\346\260\224\344\270\216\344\271\230\346\263\225\350\241\250.md" @@ -0,0 +1,42 @@ +### 笔记 + +```java +\t 制表符; +\n 换位符 +``` + +### 作业 + +```java +public class D4 { +// 购买了100立方的燃气 +// 第二阶梯燃气 4.05元/方 +// 第三阶梯燃气 5.06元/方 +// 购买金额为445.4元 +// 第二阶梯与第三阶梯各购买了多少方燃气 + public static void main(String[] args) { + for (int x=1;x<=100;x++){ + if (x*4.05 + (100-x)*5.06 == 455.4){ + System.out.println("第二阶梯燃气购买了"+x+"方,第二阶梯燃气购买了"+(100-x)+"方"); + break; + } + } + + } +} + +``` + +```java +public class D5 { + public static void main(String[] args) { + for(int i=9;i>=1;i--){ + for(int j=i;j>=1;j--){ + System.out.print(j + "x" + i + "=" + i*j + "\t"); + } + System.out.println(); + } +} +} +``` +