From 662dd86dd859aac3f1ee1e7d35ef25e1506388b1 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 18 Jul 2026 16:34:32 +0800 Subject: [PATCH] =?UTF-8?q?day05-=E6=95=B0=E7=BB=84=E7=9A=84=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=5F=E8=8E=B7=E5=8F=96=E6=95=B0=E7=BB=84=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day05/src/com/inmind/array01/Demo07.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 day05/src/com/inmind/array01/Demo07.java diff --git a/day05/src/com/inmind/array01/Demo07.java b/day05/src/com/inmind/array01/Demo07.java new file mode 100644 index 0000000..8662c54 --- /dev/null +++ b/day05/src/com/inmind/array01/Demo07.java @@ -0,0 +1,21 @@ +package com.inmind.array01; +//数组的操作_获取数组中的最大值 +public class Demo07 { + public static void main(String[] args) { + //定义一个数组 + int[] arr = {100, 120, 30, 404, 150}; + //数组中的最大值:直接与数组中每个元素比较,谁大,就记录谁 + //定义一个最大值 + int max = arr[0]; + //遍历数组,依次判断谁大 + for (int i = 1; i < arr.length; i++) { + //获取当前的元素值 + int current = arr[i]; + if (current > max) { + max = current; + } + } + System.out.println("数组中最大的值为:"+max); + + } +}