java你为啥不能复制数组 而是传递地址啊
文字
整篇文章写的很烂, 不用细看, 我就是吐槽java数组不能直接像python一样复制过去, (java是传递地址)
我把两个数组互相引用了,导致我第二次迭代的时候我以为是从a数组拿数字放到b数组,但实际上从a数组拿数字放到自己a数组
运行结果和出错代码位置
java源代码
public static void radix(int[] arr){
int n=arr.length;
int[] record=new int[n];//负责记录的数组
int[] count0_9=new int[10];//统计数字0出现次数,1出现次数,,,9出现次数
int temp;
int max = Arrays.stream(arr).max().getAsInt();
//迭代多少次
for (int exp = 1; max/exp >0; exp*=10) {//最大值999,三位数>>100,遇到999/1000=0就结束了
//统计每个数字出现次数
for (int i :
arr) {
temp = i / exp % 10;
count0_9[temp]++;
}
//划分每组上下标(共10组--> 0~9) // 例如0出现100次,0占用0~99下标, 接着1出现10次,占用100~109下标
for (int i = 1; i < 10; i++) {
count0_9[i]+=count0_9[i-1];
}
System.out.println(Arrays.toString(arr)+"######");
System.out.println(Arrays.toString(count0_9)+"############exp"+exp);
//填入中介数组/记录数组
for (int i = n-1; i >=0 ; i--) {
temp=arr[i]/exp%10;
try {
record[--count0_9[temp]]=arr[i];
}catch (Exception e){
System.out.println(e);
}finally {
System.out.println("arr下标"+i+" 数字"+arr[i]+" count下标"+count0_9[temp]);
}
}
//填完了,将record作为下一次迭代数组,并且考虑到count数组记录的下标有0,100,110等等,要清零
arr=record;
Arrays.fill(count0_9,0);
}
}