List 集合 找出最小值 和 最大 值

          import java.util.*;
          class Peng{  
              public static void main(String args[])
               {        //Double[] num = { 45.1,45.2 };
                        List dlist=new ArrayList();
                        dlist.add(45.1);
                        dlist.add(45.2);
                        dlist.add(110.22);
                        Double max = (Double)dlist.get(0);    
                        Double min = (Double)dlist.get(0);
                      for (int i = 0; i < dlist.size(); i++) {         
                                if (min > (Double)dlist.get(i)) min = (Double)dlist.get(i);  
                                 if (max < (Double)dlist.get(i)) max = (Double)dlist.get(i);       
                         }       
                                  System.out.println("max的值為" + max + "min的值為" + min);   
                }

          posted on 2007-06-26 20:50 付軒 閱讀(24189) 評論(2)  編輯  收藏

          評論

          # re: List 集合 找出最小值 和 最大 值[未登錄] 2007-12-14 20:46 Tiger

          import java.util.*;
          class Peng{
          public static void main(String args[])
          {
          List<Double> dlist=new ArrayList<Double>();
          dlist.add(45.1);
          dlist.add(45.2);
          dlist.add(110.22);
          System.out.println("max的值為: " + Collections.max(dlist) + "min的值為: " + Collections.min(dlist));
          }
          }   回復  更多評論   

          # re: List 集合 找出最小值 和 最大 值[未登錄] 2009-09-15 10:13 小強

          你使用的冒泡排序 效率很低 看看排序算法
          一個不錯的網站 介紹了一下基礎的東東http://www.family168.com/tutorial/algorithm/html/index.html  回復  更多評論   


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 贡嘎县| 二连浩特市| 宁晋县| 西安市| 西乌| 义乌市| 福州市| 巴林左旗| 共和县| 繁昌县| 彰武县| 县级市| 琼海市| 柳林县| 独山县| 集安市| 登封市| 北宁市| 冀州市| 潮安县| 汾西县| 甘洛县| 阿城市| 灵丘县| 华容县| 合阳县| 泽普县| 阜宁县| 文成县| 辽中县| 杨浦区| 外汇| 鹤庆县| 通海县| 栾川县| 二连浩特市| 酉阳| 和平县| 翼城县| 宁陵县| 阿图什市|