求教为什么不能转置。谢谢各位!
本小白财务出生,最近在自学java,刚学到数组部分,写了一个数组转置的方法 ,但输出的数组还是{7,6,5,4,3,2,1},代码如下,想请教一下哪里有问题。用同样的逻辑把sort方法直接写在主方法下运行结果又是正确的,代码如下面第二段代码,请教一下问题在哪里。自己实在想不通了。谢谢各位。
—————————————————————————————————————————————————————————
public class TestDemo{
public static void main(String args[]){
int data[]=new int[]{7,6,5,4,3,2,1};
ArryData.sort(data);
ArryData.tell(data);
}
}
class ArryData{
public static void sort(int[] arry){
int temp[]= new int[arry.length];
int foot=arry.length-1; //定义temp数组的角标
for(int x=0;x<arry.length;x++){
temp[foot]=arry[x];
foot = foot -1;
}
arry=temp;
}
public static void tell(int[] arry){
for(int x=0;x<arry.length;x++){
System.out.println(arry[x]);
}
}
}
—————————————————————————————————————————————————————————
public class TestDemo{
public static void main(String args[]){
int data[]=new int[]{7,6,5,4,3,2,1};
int temp[]= new int[data.length];
int foot=data.length-1; //定义temp数组的角标
for(int x=0;x<data.length;x++){
temp[foot]=data[x];
foot = foot -1;
}
data=temp;
ArryData.tell(data);
}
}
class ArryData{
public static void tell(int[] arry){
for(int x=0;x<arry.length;x++){
System.out.println(arry[x]);
}
}
}