黑马程序员技术交流社区

标题: 输出[1,2,3],请问有没有其他方法? [打印本页]

作者: Dencent    时间: 2016-4-20 20:38
标题: 输出[1,2,3],请问有没有其他方法?
public class Test5 {
        public static void main(String[] args) {
                int[] arr = { 1, 2, 3 };
                String s = "[";
                for (int i = 0; i < arr.length; i++) {
                        if (i == arr.length - 1) {
                                s = s + arr[i] + "]";
                        } else {
                                s = s + arr[i] + ",";
                        }
                }
                                System.out.println(s);
        }
}




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2