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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 徐瑶 中级黑马   /  2014-2-25 20:52  /  769 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

vclass ForTest
{
        public static void main(String[] args)
        {
                System.out.println(Integer.toHexString(23));
                                int x=4,y=8,z=2,max;
                                max=x>y?x:y;
                                max=max>z?max:z;

                System.out.println("max="+max);
        }
}
这个还能用其它方法完成呢?

评分

参与人数 1技术分 +1 收起 理由
zzkang0206 + 1

查看全部评分

3 个回复

倒序浏览
public class text1 {
  public static void main(String[] args) {
        List<Integer> list=new ArrayList<Integer>();
          list.add(4);
          list.add(7);
          list.add(6);
          System.out.println(Collections.max(list));
}
}

评分

参与人数 1技术分 +1 收起 理由
zzkang0206 + 1

查看全部评分

回复 使用道具 举报
用选择排序的思想,遍历一遍所以元素,找出最大,其实也差不多:
  1. class Demo
  2. {
  3.         public static void main(String[] args) throws Exception
  4.         {
  5.                 int arr[] = {5, 2, 3};
  6.                 int max = arr[0];
  7.                 for (int i = 1; i < arr.length; i++)
  8.                 {
  9.                         //遍历所有元素,只要有比max大的,就把该元素值赋给max
  10.                         if(arr[i] > max)
  11.                         {
  12.                                 max = arr[i];
  13.                         }
  14.                 }
  15.                 System.out.println("max = " + max);
  16.         }

  17. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
zzkang0206 + 1

查看全部评分

回复 使用道具 举报
哥几个,我还没学后面的啊
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马