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; } }
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
于 2023-04-15 17:40:48 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)