A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 强晨曦 中级黑马   /  2015-8-28 18:01  /  139 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

lass Test_Array1 {
        public static void main(String[]args) {

                int[] arr = {1,2,3,4,5};
                print(arr);
        }
        public static void print(int[] arr) {
                for (int x=0; x<arr.length; x++) {
                        System.out.print(arr[x]+" ");
                }
        }
}

        数组获取最值(获取数组中的最大值最小值)
class Test_Array2 {
        public static void main(String[]args) {
                int[] arr = {13,6,5,10,7,8};
                int max = printMax(arr);
                System.out.println("max="+max);
        }
        //已知数组,写一个方法,求出数组中的最大值。
        public static int printMax(int[] arr) {
                int max = arr[0];
                for (int i=1; i<arr.length; i++) {
                        if (arr[i]>max) {
                                max = arr[i];
                        }
                }
                return  max;
        }
}

7 个回复

倒序浏览
good,这个可以,复习了
回复 使用道具 举报
写的不赖  受教啦
回复 使用道具 举报
不错继续努力!
回复 使用道具 举报
谢谢分享,收藏了,哈哈哈哈
回复 使用道具 举报
{:3_46:}顶一下。。。
回复 使用道具 举报
和我写的一样!
回复 使用道具 举报
横创 来自手机 中级黑马 2015-8-28 22:28:47
8#
赞一个!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马