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


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]);

}
posted @ 2022-10-23 16:59  需求解决器  阅读(877)  评论(0)    收藏  举报