From 35751fd66b4ccb65821a71a3a85b99f9bd4ea3c0 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Mon, 21 Sep 2026 14:38:54 +0800 Subject: [PATCH] =?UTF-8?q?day07--=E5=B8=B8=E7=94=A8=E7=B1=BB-Scanner-?= =?UTF-8?q?=E7=BB=83=E4=B9=A0=5F=E5=BD=95=E5=85=A5=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=E6=95=B4=E6=95=B0=E6=B1=82=E6=9C=80=E5=A4=A7=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- day07/src/com/inmind/scanner01/Test02.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 day07/src/com/inmind/scanner01/Test02.java diff --git a/day07/src/com/inmind/scanner01/Test02.java b/day07/src/com/inmind/scanner01/Test02.java new file mode 100644 index 0000000..ded3974 --- /dev/null +++ b/day07/src/com/inmind/scanner01/Test02.java @@ -0,0 +1,31 @@ +package com.inmind.scanner01; + +import java.util.Scanner; + +//常用类-Scanner-练习2_录入三个整数求最大值(数组),注意3可以写死,最好能动态 +public class Test02 { + public static void main(String[] args) { + //1.用户手动输入求最大值的数据的数量 + Scanner sc = new Scanner(System.in); + System.out.println("请您输入要计算的整数的个数:"); + int count = sc.nextInt(); + + int[] arr = new int[count]; + + //2.动态创建数组,不停地让用户输入对应的值,并存放到数组中 + for (int i = 0; i < count; i++) { + System.out.println("请求输入第"+(i+1)+"个整数"); + int temp = sc.nextInt(); + arr[i] = temp; + } + //3.等用户输入完毕,使用数组的遍历来求最大值 + int max = arr[0]; + for (int i = 0; i < arr.length; i++) { + int temp = arr[i]; + if (temp > max) { + max = temp; + } + } + System.out.println("您输入的"+count+"个整数中,最大值为:"+max); + } +}