我需要将get1
分配到mealplan[complete][0][1]
,但是当我显示它时,只显示[null, null, null, null, null]
。 String fruits [] []和Mdtfruit [] []的示例内容为{"Apple","35","1","pc","40"}
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;
}
答案 0 :(得分:0)
数组索引从0开始,而不是1.将get1 [1]更改为get1 [0],以便进行休息。您将mealplan
声明为具有4个维度的数组,如何使用3维访问它?
答案 1 :(得分:0)
你的get1 = fruits [num]; 抛出编译错误,因为get1是字符串数组,并且您正在尝试分配String。