引元數量可變的方法

          Posted on 2007-09-19 13:06 流浪韓 閱讀(288) 評論(0)  編輯  收藏 所屬分類: J2SE

          引元數量可變的方法

          public class Test {
              public void test(String... body){

          //String...代表String的數組,長度由傳進來時的數組長度決定
                  for (int i = 0; i < body.length; i++) {
                      System.out.print(body[i]);
                  }

                  System.out.println();
              }
          }

          public class Main {
              public static void main(String[] args) {
                  Test t=new Test();
                  t.test("hello,","hi");
                  t.test("good morning");
                  t.test("good afternoon,","good evening,","good night");
              }
          }
          輸出結果:
          hello,hi
          good morning
          good afternoon,good evening,good night


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


          網站導航:
           
          主站蜘蛛池模板: 乐亭县| 吐鲁番市| 增城市| 当阳市| 务川| 灌南县| 古田县| 惠州市| 峡江县| 浦东新区| 股票| 惠水县| 海南省| 屯昌县| 桦甸市| 应用必备| 罗甸县| 凌海市| 那坡县| 宽城| 新泰市| 修文县| 高雄市| 延吉市| 清远市| 米泉市| 桦甸市| 鹰潭市| 威信县| 嘉义县| 平顺县| 大同县| 泰和县| 黑河市| 杭锦后旗| 河北区| 尖扎县| 永州市| 沁阳市| 扎鲁特旗| 秀山|