public static String myToString(int[] arr) { if (arr == null) { return null; } if (arr.length == 0) { return ""; } int i = 0; String str = "["; for (i = 0; i < arr.length-1; i++) { str += arr[i]; str += ","; } if (i == arr.length-1) { str += arr[i]; } str += "]"; return str; } public static void main(String[] args) { int[] arr = {1,2,3,7,8,9}; System.out.println(myToString(arr)); }
输出结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)