魔獸傳奇

          java程序愛好者
          posts - 28, comments - 16, trackbacks - 0, articles - 6
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          求java算法

          Posted on 2008-04-02 12:50 龍旋風 閱讀(301) 評論(2)  編輯  收藏
           一個需用2層的for循環(huán)處理的例子,誰能給出算法:
                                                                1
                                                               22
                                                              323
                                                             4234
                                                            52345

          評論

          # re: 求java算法  回復  更多評論   

          2008-04-04 18:47 by Empressement Conduct
          public class Jinzita {

          int i,j;

          public Jinzita() {
          }

          void means(){

          for(i=1; i<=5; i++){
          for(j=0; j<5-i; j++){
          System.out.print(" ");
          }

          System.out .print(i+" ");

          for(j=2; j<=i; j++){
          System.out .print(j+" ");
          }
          System.out.println();
          }
          }

          public static void main(String[] args) {
          Jinzita num = new Jinzita();
          num.means();
          }
          }


          兄弟 你試試上邊的程序 應該沒問題的
          或者 下面的程序 其實一個樣
          public class Jinzita {

          public Jinzita() {
          }

          public static void main(String[] args) {

          int i,j;
          for(i=1; i<=5; i++){
          for(j=0; j<5-i; j++){
          System.out.print(" ");
          }

          System.out .print(i+" ");

          for(j=2; j<=i; j++){
          System.out .print(j+" ");
          }
          System.out.println();
          }
          }
          }

          # re: 求java算法  回復  更多評論   

          2008-04-05 17:18 by jackiesmiht
          謝了,兄弟,測試通過!

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 凤翔县| 龙川县| 溆浦县| 延安市| 苍梧县| 广平县| 湟中县| 阳高县| 吉水县| 武功县| 西丰县| 辛集市| 阜宁县| 区。| 攀枝花市| 长岛县| 介休市| 蕉岭县| 伊金霍洛旗| 芮城县| 兴山县| 铜陵市| 林芝县| 菏泽市| 花莲县| 博爱县| 景泰县| 寿宁县| 梧州市| 谢通门县| 句容市| 兴业县| 耒阳市| 玉溪市| 彭水| 贞丰县| 美姑县| 平度市| 宣恩县| 龙山县| 六安市|