我正在尝试使用 indexOf 方法使用整数来检查字符串是否等于字符串数组的值。这是我所拥有的:
public int[] COMPONENT_IDS = { 18, 22, 20, 10, 12, 14, 16 };
public String[] COMPONENT_STRINGS = { "pie", "chocolate bar", "donut", "baguette", "triangle sandwich",
"sandwich", "bread" };
public int[][] REWARDS = { {995, 5000000}, {12852, 625000}, {8851, 1250000} };
public void handleComponents(int c) {
for(int i : COMPONENT_IDS) {
if(i == c) {
if(answer.equals(COMPONENT_STRINGS[COMPONENT_IDS.indexOf(i)]))
sendReward();
else
sendPunishment();
}
}
}
错误:
src\com\rs\game\player\content\AntiAFK.java:30: error: cannot find symbol
if(answer.equals(COMPONENT_STRINGS[COMPONENT_IDS
.indexOf(i)]))
^
symbol: method indexOf(int)
location: variable COMPONENT_IDS of type int[]