2016-11-24 20:39发布
public static void main(String[] args) { String[] arr = {"a","b","c"}; for(int i = 0; i < arr.length; i++){ System.out.print(arr[i] + ","); }}}输出结果最后多了一个, 怎么改写啊?
for(int i = 0; i < arr.length; i++){
if(i == arr.length-1){
System.out.print(arr[i]);
}else{
System.out.print(arr[i] + ",");
} }
一般我的写法
String[] arr = {"a","b","c"}; //原有的
System.out.print(arr[0]); //先输出第一个
for(int i =1; i < arr.length; i++){ //从第二个开始循环 System.out.print(","+arr[i] ); //在前面输出逗号
最多设置5个标签!
for(int i = 0; i < arr.length; i++){
if(i == arr.length-1){
System.out.print(arr[i]);
}else{
System.out.print(arr[i] + ",");
}
}
一般我的写法
String[] arr = {"a","b","c"}; //原有的
System.out.print(arr[0]); //先输出第一个
for(int i =1; i < arr.length; i++){ //从第二个开始循环
System.out.print(","+arr[i] ); //在前面输出逗号
一周热门 更多>