引元數量可變的方法

          Posted on 2007-09-19 13:06 流浪韓 閱讀(294) 評論(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


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


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 淮阳县| 弋阳县| 湘乡市| 屯门区| 重庆市| 双桥区| 柳河县| 逊克县| 安龙县| 巴青县| 重庆市| 博爱县| 天全县| 西青区| 城市| 阿瓦提县| 莒南县| 郎溪县| 海安县| 鸡东县| 南昌县| 南雄市| 句容市| 象州县| 溧阳市| 榆林市| 金湖县| 夹江县| 屯留县| 保靖县| 汉中市| 五原县| 沈丘县| 乡城县| 巴马| 天祝| 延寿县| 嘉定区| 白城市| 元江| 涟水县|