java基础训练-数组求最大值

java基础训练-数组求最大值,第1张

java基础训练-数组最大值
package itheima.create;

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 max) {
               max = a[i];
           }
        }
        return max;
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5522938.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存