I made a method converting a 2D array into a 1D array but I'm having troubling printing it. There's a problem with making a new array in the main method or calling the method. anyone can help??
public class flatten {
public static int[] flatten1(int[][] a){
int c=0;
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
c++;
}
}
int[] x = new int[c];
int k=0;
for(int i=0;i<a.length;i++){
for(int j=0;j<a[i].length;j++){
x[k++]=a[i][j];
}
}
return x;
}
public static void main(String[]args){
flatten1 f = new flatten1({{2,5,3,7,4,8},{3,4,1,2}});
for(int i=0; i<f.length;i++){
System.out.print(f[i]+" ");
}
}
}