142 将一个数组按照一定的格式以字符串的形式输出
package Demo02;//142 将一个数组按照一定的格式以字符串的形式输出
import java.util.Arrays;
public class demo06StringPractise {
public static void main(String[] args) {
int []array={1,2,3,4,5};
String str3=arrayToString(array);
System.out.println(str3);
}
public static String arrayToString (int [] array1){
String str1="[";
for (int i = 0; i < array1.length; i++) {
if(i==array1.length-1){
str1=str1+"World"+array1[i]+"]";
}else{
str1=str1+"World"+array1[i]+"#";
}
}
return str1;
}
}
/* int[]array={1,2,3};
String str1=fromArrayToString(array);
System.out.println(str1);
}
public static String fromArrayToString(int[]array){
String str="[";
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
str+=“World”+array[i]+"]";
}else{
str+="World"+array[i]+"#";
}
}
return str;*/