我需要將get1
分配到mealplan[complete][0][1]
,但是當我顯示時只顯示[null, null, null, null, null]
。字符串水果[] []和Mdtfruit [] []是{"Apple","35","1","pc","40"}
如何將String數組內容複製到java中的String數組索引中?
String[][][][] mealplan = new String[7][6][4][5];
int complete=0;
boolean finished=false;
while(!finished)
{
String[] get1=new String[4];
int num=rand.nextInt(29);
get1=fruits[num];
int t = Integer.parseInt(get1[1]);
get1[1]=String.valueOf(t*Integer.parseInt(Mdtfruit[2]));
int t2 = Integer.parseInt(get1[2]);
get1[2]=String.valueOf(t2*Integer.parseInt(Mdtfruit[2]));
int t3 = Integer.parseInt(get1[4]);
get1[4]=String.valueOf(t3*Integer.parseInt(Mdtfruit[2]));
mealplan[complete][0][1]=get1;
complete+=1;
if(complete==6)
finished=true;
}
4D數組對於尚未掌握數組索引從0開始的人來說太複雜了... – John3136