有如下语句:
String one = appendString1("字符串数据:", "腊月二十三", "除 夕", "元 宵 节", "二月二龙抬头");
System.out.println(one);
one = appendString1("Int数据:", 2, 3, 5, 7);
System.out.println(one);
one = appendString1("Float数据:", 15.2F, 16.18
F, 11.11F, 12.12F,13.13F);
System.out.println(one);
请设计编写appendString1函数,完成如下输出:
字符串数据::腊月二十三,除 夕,元 宵 节,二月二龙抬头,
Int数据::2,3,5,7,
double数据::15.2,16.18,11.11,12.12,
设计编写程序时,要在Java范围内,避免冗余代码。填写实验报告。
public class 656 {
public static void main(String[] args){
String one = appendString1("字符串数据:","腊月二十三","除夕","二月二龙抬头");
System.out.printIn(one);
one = appendString1("Int数据:" , 2, 3, 5,7);
System.out.printIn(one);
one = appendString1("Float数据", 15.2F, 16.18F, 11.11F, 12.12F, 13.13F);
System.out.printIn(one);
}
public static final String appendString1(String tag,Object...otherInfo){
String str = tag + ',';
Object[] input = otherInfo.length;
for(int i=0; i < input.length;++i){
Object item = input[i];
str = str + String.valueOf(item)+',';
}
return str;