java中的奇怪数组输出
我想知道为什么以及如何修复此数组方法输出java中的奇怪数组输出,java,arrays,output,Java,Arrays,Output,我想知道为什么以及如何修复此数组方法输出temp的内存表示形式 public class StringMethodsExersice{ public static int[] shiftMax(int[] num){ int temp[] = new int[num.length]; int firstEl = num[0]; int lastEl = num[num.length-1]; for(int i=1;i&l
temp
的内存表示形式
public class StringMethodsExersice{
public static int[] shiftMax(int[] num){
int temp[] = new int[num.length];
int firstEl = num[0];
int lastEl = num[num.length-1];
for(int i=1;i<num.length-1;i++){
if(num[i] > num[i+1]){
temp[i] = num[i];
}
temp[i] = num[i];
}
temp[0] = firstEl;
temp[num.length-1]= lastEl;
return temp;
}
public static void main (String []args){
int[] myArray = new int [5];
myArray [0] = 2;
myArray [1] = 5;
myArray [2] = 6;
myArray [3] = 14;
myArray [4] = 25;
System.out.println(shiftMax(myArray));
}
}
公共类StringMethodsVersion{
公共静态int[]shiftMax(int[]num){
int temp[]=新int[num.length];
int firstEl=num[0];
int lastEl=num[num.length-1];
for(int i=1;i num[i+1]){
temp[i]=num[i];
}
temp[i]=num[i];
}
温度[0]=firstEl;
温度[num.length-1]=lastEl;
返回温度;
}
公共静态void main(字符串[]args){
int[]myArray=新的int[5];
myArray[0]=2;
myArray[1]=5;
myArray[2]=6;
myArray[3]=14;
myArray[4]=25;
System.out.println(shiftMax(myArray));
}
}
您可以使用:
(详情请参阅)
关于您获得的输出的说明: 由于每个对象都有
toString()
方法,因此默认情况下显示类名表示,然后添加@
符号,然后添加hashcode。您可以使用:
(详情请参阅)
关于您获得的输出的说明:
由于每个对象都有
toString()
方法,因此默认情况下显示类名表示,然后添加@
符号,然后添加hashcode。停止窃取我的答案!:P+1还请注意,对于嵌入式系统,存在数组。deepToString()
arrays@BogGogo如果答案对你有帮助,请接受。别再偷我的答案了!:P+1还请注意,对于嵌入式系统,存在数组。deepToString()
arrays@BogGogo如果答案对你有帮助,请接受。
System.out.println(Arrays.toString(shiftMax(myArray)));