码迷,mamicode.com
首页 > 编程语言 > 详细

数组获取最大值

时间:2019-07-14 19:46:47      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:image   system   out   info   span   max   string   style   oid   

数组获取最大值:

class Hello2 {
    public static void main(String[] args) {
        int[] arr = {11,12,13,14,15};
        int max = getMax(arr);
        System.out.println("max =" + max);
        
    }
    public static int getMax(int[] arr) {
        int max = arr[0];
        for (int i = 1;i < arr.length ;i++ )
        {
            if (max < arr[i])
            {
                max = arr[i];
            }
        }
        return max;
    }

}

结果:

技术图片

 

数组获取最大值

标签:image   system   out   info   span   max   string   style   oid   

原文地址:https://www.cnblogs.com/Wangzui1127/p/11185177.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!