[code]/*
用方法做数组的反转
*/
class Test2 {
public static void main(String[] args) {
int arr1[]={1,2,3,4,5,6};
//reverse(arr);
print(arr1);
/*for (int i = 1; i <arr.length ;i++ ) {
System.out.print(arr[i]+' ');
}*/
}
/*
1,明确返回值类型,因为是输出语句,没有返回值,所以用void
2,明确参数列表,int[] arr
*/
/*public static void reverse(int[] arr){
for (int i = 0;i < arr.length/2 ;i++ ) {
int temp;
temp = arr[i]; //确定数组的首位做交换
arr[i] = arr[arr.length-1-i];
arr[arr.length-1-i] = temp;
}
}*/
//做一个数组遍历
public static void print(int[] arr){
for (int i = 0;i < arr.length ;i++ ) {
System.out.print(arr[i]+' ');
}
}
} |
|