1.复制数组
int[] arr1 = {14, 7, 12, 22, 30, 9};
int[] arr2 = new int[5];
arr2 = Arrays.copyOfRange(arr1, 0, 4);
for(int a : arr1) { System.out.print(a + " "); }
System.out.println();
for(int b : arr2) { System.out.print(b + " "); }
2.输出数组中最小的数
1 int arr[] = {14, 7, 12, 22, 30, 9}; 2 for(int a = 1; a < arr.length; a++) 3 { 4 for(int b = 0; b < arr.length - 1; b++) 5 { 6 if(arr[b] > arr[b + 1]) 7 { 8 int h = arr[b + 1]; 9 arr[b + 1] = arr[b]; 10 arr[b] = h; 11 } 12 } 13 } 14 System.out.println(arr[0]);
3.替换数组
1 String tr = "bb"; 2 String []wow = new String []{"jhg", "kf", "jj", "hg", "rt", "ute"}; 3 for(int a = 0; a < wow.length; a++) 4 { 5 System.out.print(wow[a] + " "); 6 } 7 Arrays.fill(wow, 2, 3, tr); 8 9 System.out.println(); 10 for(int a = 0; a < wow.length; a++) 11 { 12 System.out.print(wow[a] + " "); 13 }
4,二维数组调换顺序输出
1 int[][] a = new int[3][3]; 2 a[0] = new int[]{1, 2, 3}; 3 a[1] = new int[]{4, 5, 6}; 4 a[2] = new int[]{7, 8, 9}; 5 6 for(int x = 0; x < a.length; x++) 7 { 8 for(int y = 0; y < a.length; y++) 9 { 10 System.out.print(a[x][y] + " "); 11 } 12 System.out.println(); 13 } 14 for(int x = 0; x < a.length; x++) 15 { 16 for(int y = 0; y < a.length; y++) 17 { 18 System.out.print(a[y][x] + " "); 19 } 20 System.out.println();