题目:将一个数组逆序输出。
代码:
/**
* 数组逆序输出
* @author cheng
*
*/
public class ThirtyOne {
public void converse(int[] a){
int[] b=new int[a.length];
for(int i=0;i<a.length;i++){
b[i]=a[a.length-i-1];
System.out.println(b[i]);
}
}
public static void main(String[] args) {
int[] a={1,2,3,4,5,6};
ThirtyOne thirtyOne=new ThirtyOne();
thirtyOne.converse(a);
}
}
输出结果:
6
5
4
3
2
1