1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public class AdvancedArray { public static void main(String[] atgs){ int[] arr1 = {1,2,3,4,5}; int[] tmp1 = arr1; int[] tmp2 = arr1; System.out.print("透過tmp1去出陣列:"); for(int i = 0 ; i < tmp1.length ; i++) System.out.print(tmp1[i] + " "); System.out.print("\n透過tmp2去出陣列:"); for(int i = 0 ; i < tmp1.length ; i++) System.out.print(tmp2[i] + " "); tmp1[2] = 9; System.out.print("\n\n透過tmp1取出陣列:"); for(int i = 0 ; i < tmp1.length ; i++) System.out.print(tmp1[i] + " "); System.out.print("\n透過tmp2去出陣列:"); for(int i = 0 ; i < tmp1.length ; i++) System.out.print(tmp2[i] + " "); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class AdvancedArray2 { public static void main(String[] args){ int[] arr1 = {1,2,3,4,5}; int[] arr2 = {5,6,7}; int[] tmp = arr1; System.out.print("使用tmp取出arr1中的數列"); for(int i = 0 ; i < tmp.length ; i++) System.out.print(tmp[i] + " "); tmp = arr2; System.out.print("\n使用tmp取出arr2中的數列"); for(int i = 0 ; i < tmp.length ; i++) System.out.print(tmp[i] + " "); } |
0 意見:
張貼留言