import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] array = new int[]{11,22,33,44,55,66,77,88,99};
//面向对象思想遍历打印
System.out.println(Arrays.toString(array));
//面向过程编程思想
printArray(array);
}
public static int[] printArray(int[] array){
System.out.print("[");
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
System.out.print(array[i]);
}else if(i==0){
System.out.print(array[i]+", ");
}else{
System.out.print(array[i]+", ");
}
}
System.out.println("]");
return array;
}
}
java用面向对象和面向过程思想实现两个方法,遍历打印数组,要求结果为数组形式
最新推荐文章于 2022-09-27 15:07:05 发布