要求输出格式为[98,23,16,35,72] 有没有简单的方法了
- class home{
- public static void arr(int[] arr){
- System.out.print("[");
- for (int i = 0; i < arr.length; i++) {
- if (i == arr.length-1) {
- System.out.print(arr[i]);
- }else{
- System.out.print(arr[i]+",");
- }
-
- }
- System.out.println("]");
- }
- public class homework {
-
- public static void main(String[] args) {
- int[] arr = {98,23,16,35,72};
- home.arr(arr);
-
- }
- }
复制代码 |
|