package itheima.create;/* * @author HuWen * @date 2021/11/1721:46 * @version 1.0 *加油每天坚持学习 */ public class ArrayMax { public static void main(String[] args) { //求数组中的最大值 int [] ages = {1,32,232,5,546,4,777,0,7}; // 定义个需要求解的数组 int max =arrayMax(ages); // 定义最大值 System.out.println(max); } public static int arrayMax(int []a){ //找出数组中的最大值返回 int max = a[0]; //遍历数组的数据 for (int i = 0; i <a.length ; i++) { if (a[i]>max) { max = a[i]; } } return max; } }
java基础训练-数组求最大值
最新推荐文章于 2024-01-16 18:25:59 发布