【发布时间】:2014-03-25 23:07:52
【问题描述】:
提示:编写一个反转数组中元素序列的方法。
例如,如果你用数组调用方法
1 4 9 16 9 7 4 9 11
然后数组变为
11 9 4 7 9 16 9 4 1
这是我目前所拥有的。我不知道如何调用该方法...
public static void main(String[] args) {
int [] array = {1,4,9,16,9,7,4,9,11};
System.out.println(reverse(array[]));
}
public static void reverse (int[]a){
for (int i = 0; i < a.length/2; i++){
double temp = a[i];
a[i] = a[a.length - i -1];
temp = a[a.length - i - 1];
}
}
【问题讨论】:
-
阅读错误信息;它会准确地说出什么是错的。 (嗯,其中一件事。)