package com.heima.work;
public class Demo1_Work {
public static void main(String[] args) {
int[] arr = {12,31,45,67,12};
System.out.println(toString(arr));
}
public static String toString(int[] arr) {
if(arr == null) {
return null;
}
if(arr.length == 0) {
return "[]";
}
String line = "[";
for (int i = 0; i < arr.length; i++) {
if(i == arr.length - 1) {
line = line + arr[i] + "]";
}else {
line = line + arr[i] + ", ";
}
}
return line;
}
} |
|