首页 > 其他分享 >① 定义一个大小为10 的整形数组a; ② 从键盘输入10 个整数,放置到数组a 中; ③ 输出数组a 中的最大值。 注意:使用数组、循环结构语句实现。

① 定义一个大小为10 的整形数组a; ② 从键盘输入10 个整数,放置到数组a 中; ③ 输出数组a 中的最大值。 注意:使用数组、循环结构语句实现。

时间:2022-10-23 17:15:17浏览次数:42  
标签:10 int 最大值 System 键盘输入 数组 input


public static void main(String[] args) {
	Scanner input=new Scanner(System.in);
	int[] a=new int[10];//定义一个数组
	//给数组的10个元素赋值
	for (int i = 0; i < a.length; i++) {
		System.out.println("请输入第"+(i+1)+"个值:");
		a[i]=input.nextInt();
		
	}
	Arrays.sort(a);//排序,默认从小到大排序
	System.out.println("数组的最大值:"+a[a.length-1]);

}

标签:10,int,最大值,System,键盘输入,数组,input
From: https://www.cnblogs.com/jiahaozhang/p/16818899.html

相关文章