From 293769366a5f2441ea9a68a7a6b5f45c137bbfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <3159961255@qq.com> Date: Thu, 8 Dec 2022 22:48:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=95=B0=E7=BB=84=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\347\273\204\344\275\234\344\270\232.md" | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20221207 \346\225\260\347\273\204\344\275\234\344\270\232.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20221207 \346\225\260\347\273\204\344\275\234\344\270\232.md" "b/20 \347\237\263\350\211\257\346\266\233/20221207 \346\225\260\347\273\204\344\275\234\344\270\232.md" new file mode 100644 index 0000000..8d8a46e --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20221207 \346\225\260\347\273\204\344\275\234\344\270\232.md" @@ -0,0 +1,36 @@ +# 数组作业 + +```java +import java.util.Scanner; + +public class A8 { + + +//需求:定义一个可以存储5个元素的int数组,数据来自于键盘录入,最后遍历数组,把元素输出在控制台 +//分析: +//① 数组长度可知,元素未知,采用动态初始化 +//② 键盘录入,使用Scanner实现 +public class D1 { + + public static void main(String[] args) { + Scanner sce=new Scanner(System.in); + System.out.println("请输入第一个整数:"); + int one = sce.nextInt(); + System.out.println("请输入第二个整数:"); + int two = sce.nextInt(); + System.out.println("请输入第三个整数:"); + int three = sce.nextInt(); + System.out.println("请输入第四个整数:"); + int four = sce.nextInt(); + System.out.println("请输入第五个整数:"); + int five = sce.nextInt(); + + int[]arr={one,two,three,four,five}; + for (int i=0;i<5;i++){ + System.out.println("你输入的数字分别是:"+arr[i]); + } + } +} + +} +``` -- Gitee From 9cdcff9743bba43ff292f63d62b79228b2d857c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E8=89=AF=E6=B6=9B?= <3159961255@qq.com> Date: Tue, 13 Dec 2022 13:05:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?20221209=20=E9=9A=8F=E6=9C=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\347\273\204\344\275\234\344\270\232.md" | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 "20 \347\237\263\350\211\257\346\266\233/20221209 \351\232\217\346\234\272\346\225\260\347\273\204\344\275\234\344\270\232.md" diff --git "a/20 \347\237\263\350\211\257\346\266\233/20221209 \351\232\217\346\234\272\346\225\260\347\273\204\344\275\234\344\270\232.md" "b/20 \347\237\263\350\211\257\346\266\233/20221209 \351\232\217\346\234\272\346\225\260\347\273\204\344\275\234\344\270\232.md" new file mode 100644 index 0000000..7eaf674 --- /dev/null +++ "b/20 \347\237\263\350\211\257\346\266\233/20221209 \351\232\217\346\234\272\346\225\260\347\273\204\344\275\234\344\270\232.md" @@ -0,0 +1,44 @@ +### 作业 + +作业1 + +```java + import java.util.Random; + + public class A9 { + 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] + " "); + } + } + } +``` + +作业2 + +```java + import java.util.Scanner; + + public class A10 { + 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]); + } + } + } +``` + + -- Gitee