當前位置:成語大全網 - 新華字典 - 詢問數組中Java中foreach語句的可變長度

詢問數組中Java中foreach語句的可變長度

int?arr[][]?=?新的?int[][]?{{4,3},{1,2}};

for(int?x[]:arr)?{

for(int?e:x)?{

//這裏e的值可能是:4,3,1,2?x.length是常數:2。

//最後2?==?2?所以不輸出,號。

if(e==x.length)?{

system . out . print;

}別的?{

System.out.print(e?+?"、");

}

}

}可能妳不太明白for的用法,我舉個栗子:

String[]?物品?=?{“妳”、“好”、“真的”};

//這裏的項是什麽意思?數組中的每個值

for(字符串?item:items){

system . out . print(item);

}

//輸出:妳好嗎?