// Write a method to receive 3 parameters: an array of integer number , and integer value: low, integer value: high. the method will create new array copy all values tat are between low and high into new array. the method will return the new array upon completion
// write a method to received 2 parameter. one dimensional array of integers, inter value: row
// method to create 2D whose number of rows is equal to row, it will copy all values from 1D into new array. method will return the new array upon completion
public static int[] copyArray(int[] in, int low, int high) { int count = 0; for (int i = 0; i < in.length; i++) { if (in[i] >= low && in[i] <= high) { count++; } } int[] out = new int[count]; count = 0; for (int i = 0; i < in.length; i++) { if (in[i] >= low && in[i] <= high) { out[count] = in[i]; count++; } } return out; }
public static int[][] copy2D(int[] in, int row) { int[][] out = new int[row][in.length]; for (int i = 0; i < row; i++) { out[i] = in; } return out; }
Comments