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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© wangyuyus 中级黑马   /  2013-11-20 13:24  /  982 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

输入数组,最大的于第一个元素交换,最小的与最后一个元素交换,输出数组。请问这个应当如何编写呀
public class test {
    public static void main(String[] args){
                 List arr = new ArrayList();
                 arr.add(34);
                 arr.add(76);
                 arr.add(24);
                 arr.add(135);
                 arr.add(98);
                 int i = 0 ,j=0;
                 Iterator it =arr.iterator();
                 if(it.hasNext())
                 i=j=(Integer) it.next();
                 while(it.hasNext()){
                         int in = (Integer) it.next();
                         if(i>in){
                                 i=in;
                         }
                         if(j<in){
                                 j=in;
                         }
                 }
                 System.out.println(i+":"+j);

    }
}


评分

参与人数 1技术分 +1 收起 理由
黄炳期 + 1

查看全部评分

3 个回复

倒序浏览
既然要操作数组,直接操作不就完了么。干嘛还要放到集合
回复 使用道具 举报
如果问题已经解决,请及时修改主题为“提问结束”。
修改主题的方法链接
http://bbs.itheima.com/thread-89313-1-1.html
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马