我刚开始Java,我不明白为什么这段代码:
char WORDS[][] = {"jazz", "buzz", "hajj", "fuzz", "jinx", "jazzy", "fuzzy", "faffs", "fizzy", "jiffs", "jazzed", "buzzed", "jazzes", "faffed", "fizzed", "jazzing", "buzzing", "jazzier", "faffing", "fuzzing"};
char comp[] = WORDS[rand.nextInt(WORDS.length)];
char compHidden[comp.length];
产生此错误:
- Syntax error on token "[", = expected
- Type mismatch: cannot convert from int
to char
- Syntax error on token "]", delete this
token
都在第三行。为什么是这样?还有另一种方法可以找到 char 数组的长度吗?