我正在做一些Java代碼的挑戰,並試圖寫整個類/構造函數和main(),而不是一個常規的方法只是爲了得到一些額外的做法。已經嘗試在Eclipse和JGrasp中運行它,並得到相同的輸出:[I @ 6d06d69c簡單的數組類工作,但給出錯誤的輸出
有沒有人有線索,我做錯了什麼?在此先感謝您的幫助:)
/*
Given an int array, return a new array with double the
length where its last element is the same as the original
array, and all the other elements are 0. The original
array will be length 1 or more. Note: by default, a
new int array contains all 0's.
makeLast({4, 5, 6}) → {0, 0, 0, 0, 0, 6}
makeLast({1, 2}) → {0, 0, 0, 2}
makeLast({3}) → {0, 3}
*/
public class MakeLast {
public MakeLast(int[]nums){
int[] result = new int[nums.length *2];
result[result.length-1] = nums[nums.length-1];
System.out.println(result);
}
public static void main(String[] args) {
int[] nums = {3, 5, 35, 23};
new MakeLast(nums);
}
}