java:用键盘上输入几个数,并从中找出最大值

import java.util.Scanner;

public class Fighting {

	public static void main(String[] args) {
		int max = 0;
		Scanner scanner = new Scanner(System.in);
		System.out.println("请问有几个数:");
		int number = scanner.nextInt();
		System.out.println("请输入这"+number+"个数字:");
		int[] arr = new int[number];
		for(int i = 0;i < arr.length;i++) {
			arr[i] = scanner.nextInt();
			if(arr[i]>max) {
				max = arr[i];
			}
		}		
		System.out.println("输入的最大数是:"+max);
	}
}

java:用键盘上输入几个数,并从中找出最大值_第1张图片

你可能感兴趣的:(java2020,java)