1
以下是代碼片段:爪哇 - 引用到數組
int[] cdb1 = {2,1,1,5,5};
int[] cbd2 = {3,1,1,2,2,6,6};
int[] cbd3 = {3,2,2,3,3,7,7};
int[] cbd4 = {2,3,3,4,4};
int[] cbd5 = {4,4,4,5,5,6,6,7,7};
String this_cdb = "cdb"+Integer.toString(router_id);
int this_cbd_number = this_cdb[0];
我收到以下錯誤:數組必需的,但字符串發現 int this_cbd_number = this_cdb[0];
這裏router_id
可以1
2
3
4
或5
。我知道我宣稱this_cdb
爲String
。但是,我如何將它引用到正確的數組名稱?
它應該是[router_id-1]對不對? – hnvasa
是的,你是對的,更正 –