Package Javafirst;import java.util.Arrays;
Class Show{public void Showarray (int[] arr) {for (int i:arr) {System.out.print (i + "");} System.out.println ();}}
public class Arraytest {public static void main (string[] args) {Show sh = new Show ();//Exercise one arr1 copy 0~3 elements to arr2 (four numbers) int[] Arr 1 = {1,2,3,4,5,6};int ARR2[];ARR2 = Arrays.copyofrange (arr1, 0,4); Sh.showarray (ARR2); System.out.println ("\ n Exercise II");//exercise the minimum number of output array, the method of arrays class is simple some arrays.sort (arr1); System.out.println ("The smallest number is" +arr1[0 "+" \ n exercise three ");//exercise three replace position 2 element String arrstr[] = new string[]{" abc "," ADC "," SDC "," BCD "}; for (String str:arrstr) {System.out.print (str + "");} System.out.println ("\ n position 2 replaced:"); Arrays.fill (arrstr, 2,3, "BB"); for (String str:arrstr) {System.out.print (str + "");} System.out.println ("\ n exercise four");//Exercise 42-D array row and column intermodulation int[][] arr3 = {{1,2,3},{4,5,6},{7,8,9}}; System.out.println ("swap Before"), for (int i = 0; i < arr3.length; i++) {for (int k = 0; k < arr3[i].length; k++) {SYSTEM.OUT.PR Int (Arr3[i][k] + "");} System.out.println ();} System.out.println ("reversed"); for (int i = 0; i < arr3.length; i++) {for (int k = 0; k < arr3[i].length; k++) {SYSTEM.OUT.PR Int (Arr3[k][i] + "");} System.out.println ();}}}
Output results
Java array after class exercises