Respuesta :
Answer:
The method is written in Java
public static String return1D(String [][] D2) {
int k =0;
String D1[] = new String[D2.length * D2[0].length];
for (int row = 0; row < D2.length; row++) {
for (int column = 0; column < D2[row].length; column++) {
D1[k] = D2[row][column];
k++;
}
}
for(int i = 0;i<k;i++){
System.out.print(D1[i]);
}
return " ";
}
Explanation:
See attachment for complete program that includes the main method.
However, the line by line explanation of the function is as follows
This line defines the method
public static String return1D(String [][] D2) {
This line initializes the count variable k to 0
int k =0;
This line defines the 1 dimensional array
String D1[] = new String[D2.length * D2[0].length];
The following iterates through the row
for (int row = 0; row < D2.length; row++) {
The following iterates through the column
for (int column = 0; column < D2[row].length; column++) {
This line gets all rows and columns in 1 dimensional array
D1[k] = D2[row][column];
The counter is incremented here
k++;
}
}
The following iteration prints the 1 Dimensional array
for(int i = 0;i<k;i++){
System.out.print(D1[i]);
}
return " ";
}