JAVA可变个数形参测试------JAVA入门基础教程

public class Test
{
    public static void main(String[] args)
    {
        Test t = new Test();
        String info = t.concat("-","Hello","World");
        String info1 = t.concat("/","Hello");
        System.out.println(info);
        System.out.println(info1);
    }
    public String concat(String operator,String ...str)
    {
        String result = "";
        for (int i = 0; i < str.length; i++)
        {
            if(i == 0)
            {
                result = result + str[i];
            }
            else
            {
                result = result + operator + str[i];
            }
        }
        return result;
    }
}

你可能感兴趣的:(JAVA随手写,java,数据结构,intellij-idea,eclipse,开发语言)