From 262896711486a412ae2f425c7b7c5fa2a9825667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=A8=81=E6=96=8C?= <2016807083@qq.com> Date: Wed, 5 Apr 2023 21:07:24 +0800 Subject: [PATCH] =?UTF-8?q?20230404=20=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 --- ...\347\273\204\344\275\234\344\270\232 A.md" | 127 ++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 "09 \347\216\213\345\250\201\346\226\214/20230404 \346\225\260\347\273\204\344\275\234\344\270\232 A.md" diff --git "a/09 \347\216\213\345\250\201\346\226\214/20230404 \346\225\260\347\273\204\344\275\234\344\270\232 A.md" "b/09 \347\216\213\345\250\201\346\226\214/20230404 \346\225\260\347\273\204\344\275\234\344\270\232 A.md" new file mode 100644 index 0000000..44efabe --- /dev/null +++ "b/09 \347\216\213\345\250\201\346\226\214/20230404 \346\225\260\347\273\204\344\275\234\344\270\232 A.md" @@ -0,0 +1,127 @@ +## 编码题 + +**1.定义一个含有五个元素的数组,并为每个元素赋值,求数组中所有元素的最小值** + +**操作步骤:** + +​ 1.定义5个元素数组 + +​ 2.可以使用初始化数组的两种方式之一为数组元素赋值 + +​ 3.遍历数组求数组中的最小值 + +``` + public static void main(String[] args) { + int[] a={2,3,4,67,4}; + int min=a[0]; + for (int i = 0; i < a.length; i++) { + if (min>a[i]){ + min=a[i]; + } + } + System.out.println(Arrays.toString(a)); + System.out.println("最小值="+min); + + } +``` + +**2.需求:求出数组中索引与索引对应的元素都是奇数的元素** + +**分析:** + +​ 1、遍历数组 + +​ 2、判断索引是否是奇数(索引 % 2 != 0) + +​ 3、判断索引对应的元素是否是奇数(arr[索引] % 2 != 0) + +​ 4、满足条件输出结果 + +``` + public static void main(String[] args) { + int[] a={1,2,3,4,5,9,7,11,90,10,31}; + System.out.println(Arrays.toString(a)); + System.out.print("索引与索引对应的元素都是奇数的元素:"); + for (int i = 0; i