69 620
Assignments Done
99,3%
Successfully Done
In February 2019

Answer to Question #58913 in Java | JSP | JSF for Sherlynn

Question #58913
// 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 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;
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!