package Eleventh; import java.util.*; //寻找最大数经常在计算机应用程序中使用。例如:确定销售竞赛优胜者的程序要输入每个销售员的销售量, // 销量最大的员工为销售竞赛的优胜者, // 请你帮忙找到最大的数并且打印这个数。例如输入:1,8,9,10,12,45,6 输出45 public class one { public static void main(String[] args) { System.out.print("请输入一组数字(每一个数字请用空格隔开):"); Scanner sc = new Scanner(System.in); String [] str = sc.nextLine().split(" "); int [] array = new int[str.length]; for(int i = 0;i<str.length;i++) { array[i] = Integer.parseInt(str[i]); } int max = array[0]; for(int j = 0;j<array.length;j++) { if(max<array[j]) { max = array[j]; } } System.out.println("这一组最大的数字是"+max); } }
原文:https://www.cnblogs.com/chenjiajiale/p/12546373.html