魔獸傳奇

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

          求java算法

          Posted on 2008-04-02 12:50 龍旋風 閱讀(301) 評論(2)  編輯  收藏
           一個需用2層的for循環處理的例子,誰能給出算法:
                                                                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
          謝了,兄弟,測試通過!

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


          網站導航:
           
          主站蜘蛛池模板: 财经| 上饶市| 长岛县| 苍溪县| 昌邑市| 会泽县| 兴仁县| 甘孜| 濉溪县| 当涂县| 福建省| 宜城市| 措勤县| 长沙县| 长治市| 宾川县| 汝城县| 富裕县| 易门县| 白城市| 察雅县| 柳江县| 扎兰屯市| 兴文县| 张北县| 霞浦县| 石渠县| 延庆县| 巢湖市| 丹江口市| 奇台县| 承德市| 长岭县| 瑞昌市| 江西省| 奉化市| 余姚市| 石家庄市| 扎鲁特旗| 澎湖县| 安乡县|