zoukankan      html  css  js  c++  java
  • java可变参数列表

     1 public class Test {
     2     static void list(Integer[] i) {
     3         for (Integer q : i) {
     4             System.out.print(q + "*");
     5         }
     6         System.out.println();
     7     }
     8     static void list(String...args){
     9         for (String q : args) {
    10             System.out.print(q + "*");
    11         }
    12         System.out.println();
    13     }
    14     static void list(Integer a,String...args){     //添加不可变参数,防止方法调用矛盾
    15         System.out.print(a+"*");
    16         for (String q : args) {
    17             System.out.print(q + "*");
    18         }
    19         System.out.println();
    20     }
    21     public static void main(String[] args) {
    22 
    23         Integer[] in = new Integer[] { 1, 2, 3, 4, 5, 1, 7, 100 +'a'};    //可变参数
    24         list(in);
    25         list();
    26         list("ff","ds","df","h","hgg");
    27         list(2,"rtr","er","tr","we");
    28         
    29     }
    30 }

                                           附图:输出结果

  • 相关阅读:
    CF Round433 B. Jury Meeting
    CF Round433 C. Planning
    繁忙的都市
    联络员
    组合数模板
    Rinne Loves Xor
    [SDOI2016]齿轮
    水题(water)
    Music Problem
    小H和游戏
  • 原文地址:https://www.cnblogs.com/huanglibin/p/2760470.html
Copyright © 2011-2022 走看看