I just want to initialize a 2D array with 1D array values which is in a loop... like
for (int i=0; i<=x ; i++){ // x will be taken by user input(Scanner)
for (int j=0; j<=3; j++){
char s[][] = new char[x][6];
System.out.println("Enter value a : ");
a = input.nextInt();
if (a==1){
char r[] = {'A','B','C','D','E','F'};
s[i][j] = r ; // **Here is where I'm stuck at...**
}
else if (a==2){
char r[] = {'G','H','I','J','K','L'};
s[i][j] = r ; // **Here is where I'm stuck at...**
}
}
}
I want my final 2D array as below for following the inputs x=2 a=1,a=2 &a=1
s[][]={{'A','B','C','D','E','F'},{'G','H','I','J','K','L'},{'A','B','C','D','E','F'}};
Please correct me If I was asking impossible one... Or provide me another method to get such result.... Thank you
s[i][j] = rwould not be creating a 2d array. it'd be creating a 3 D array.s[i] = rwould be 2d.char[][]is a 2D array and achar[][][]is a 3D array.