public class Main {
public static void main(String[] args) {
int[] in = {1, 7, 5, 8, 9, 12, 256, 25};
int[] test1 = copyArray(in, 6, 12);
int[][] test2 = copy2D(in, 6);
}
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
Leave a comment