從制造到創(chuàng)造
          軟件工程師成長(zhǎng)之路
          posts - 292,  comments - 96,  trackbacks - 0


          import java.util.ArrayList;
          import java.util.List;

          public class Sum {
              
          public static void main(String[] args) {

                  
          int[] temp = new int[1000];
                  
          for (int i = 1; i < 1001; i++) {
                      temp[i 
          - 1= i;
                  }

                  
          int total = 0;// 存儲(chǔ)總數(shù)
                  int sum = 0// 和
                  int k = 0;
                  List list 
          = null// 存儲(chǔ)每次新循環(huán)時(shí)的數(shù)據(jù)
                  int size = 0;
                  
          int num = 0;
                  
          for (int j = 0; j < 1000; j++) {
                      k 
          = j;
                      sum 
          = 0// sum 每次循環(huán)都要重置
                      list = new ArrayList(); // list 每次循環(huán)都要清空
                      do {
                          sum 
          += temp[k];

                          list.add(temp[k]);
                          
          if (sum == 1000) {// 洽好等于1000就打印
                              total++;
                              System.out.println(
          "Group" + total + ":  ");
                              
          if (list != null && list.size() > 0) {
                                  size 
          = list.size();
                              }
                              
          for (int x = 0; x < size; x++) {
                                  num 
          = x + 1;
                                  System.out.println(
          "    " + num + " : " + list.get(x));
                              }
                          }

                          
          if (k < 999) {
                              k
          ++;
                          }
                      } 
          while (sum < 1001);// 超過(guò)1000就退出
                  }

                  System.out.println(
          "  total :  " + total);
              }
          }


          輸出結(jié)果:

          Group1:  
              
          1 : 28
              
          2 : 29
              
          3 : 30
              
          4 : 31
              
          5 : 32
              
          6 : 33
              
          7 : 34
              
          8 : 35
              
          9 : 36
              
          10 : 37
              
          11 : 38
              
          12 : 39
              
          13 : 40
              
          14 : 41
              
          15 : 42
              
          16 : 43
              
          17 : 44
              
          18 : 45
              
          19 : 46
              
          20 : 47
              
          21 : 48
              
          22 : 49
              
          23 : 50
              
          24 : 51
              
          25 : 52
          Group2:  
              
          1 : 55
              
          2 : 56
              
          3 : 57
              
          4 : 58
              
          5 : 59
              
          6 : 60
              
          7 : 61
              
          8 : 62
              
          9 : 63
              
          10 : 64
              
          11 : 65
              
          12 : 66
              
          13 : 67
              
          14 : 68
              
          15 : 69
              
          16 : 70
          Group3:  
              
          1 : 198
              
          2 : 199
              
          3 : 200
              
          4 : 201
              
          5 : 202
          Group4:  
              
          1 : 1000
            total :  
          4
          posted on 2007-07-20 14:49 CoderDream 閱讀(1495) 評(píng)論(0)  編輯  收藏 所屬分類: 經(jīng)驗(yàn)點(diǎn)滴

          <2007年7月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234

          常用鏈接

          留言簿(9)

          我參與的團(tuán)隊(duì)

          隨筆分類(245)

          隨筆檔案(239)

          文章分類(3)

          文章檔案(3)

          收藏夾(576)

          友情鏈接

          搜索

          •  

          積分與排名

          • 積分 - 458389
          • 排名 - 114

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 金华市| 嘉祥县| 惠东县| 曲麻莱县| 青冈县| 昌宁县| 西城区| 南和县| 南宫市| 鄯善县| 洛宁县| 含山县| 河北区| 府谷县| 兴义市| 湘阴县| 阳曲县| 惠来县| 吴桥县| 开平市| 阿拉尔市| 九龙坡区| 锡林浩特市| 湛江市| 临洮县| 丹阳市| 崇阳县| 元阳县| 台中市| 敦化市| 万荣县| 七台河市| 长岛县| 钟祥市| 平阴县| 团风县| 南丰县| 德化县| 磐石市| 新巴尔虎左旗| 阜阳市|