魔獸傳奇

          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
          謝了,兄弟,測試通過!

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


          網站導航:
           
          主站蜘蛛池模板: 青阳县| 德惠市| 连云港市| 永修县| 墨竹工卡县| 包头市| 普陀区| 乳山市| 武义县| 确山县| 兴化市| 龙井市| 且末县| 乌鲁木齐县| 上蔡县| 富川| 泾川县| 遂平县| 呼和浩特市| 东城区| 广河县| 祁门县| 嵩明县| 贺兰县| 宁河县| 徐汇区| 余姚市| 湘潭县| 元阳县| 清原| 河北省| 南开区| 霍林郭勒市| 高雄县| 镇沅| 镇原县| 罗甸县| 马山县| 金寨县| 正镶白旗| 青铜峡市|