Question #59017

write a method to receive 2 parameter: 1D array of integer number, integer value (row)
method to create 2D whose number of rows is equal to row. the method will copy all values from 1D array into new array. the array will return the new array upon completion

Expert's answer

package javaapplication5;
import java.util.*;
public class JavaApplication5 {
static int[][] Met(int[]arr,int row)
{
int[][] res = new int[row][arr.length];
for (int i = 0; i < row; i++) {
for (int j = 0; j < arr.length; j++) {
res[i][j] = arr[j];
}
}
for (int i = 0; i < row; i++) {
for (int j = 0; j <res[i].length; j++) {
System.out.print(res[i][j]);
if(j==arr.length-1)System.out.println();
}
}
return res;
}
public static void main(String[] args) {
int[]arr = new int[4];
for (int i = 0; i < 4; i++) {
arr[i] = i;
}
int[][]mas = Met(arr,5);
}
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS