我正在尝试创建一个函数,该函数将从字母表中随机生成字母,用户需要输入“A”作为元音字母和“B”作为辅音。然后系统将通过从数组中搜索字母来检查答案是否正确。
但是,我收到此错误:
找不到标志
符号:方法 indexOf(char)
请在下面检查我的代码。
public static void Exam_LetterType() throws Exception
{
BufferedReader temp = new BufferedReader(new InputStreamReader(System.in));
String Alphabet[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
String Vowel[]={"a","e","i","o","u"};
String Consonant[]={"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"};
Random x = new Random();
int Index;
String Answer;
int CorrectAnswer = 0;
for(int i=1;i<=20;i++)
{
Index = x.nextInt(26);
System.out.println ("\n A) VOWEL LETTER B) CONSONANT LETTER");
System.out.print(" Letter" + "'" + Alphabet[Index] + "'" + " is a: ");
String Question = Alphabet[Index];
Answer = temp.readLine();
if(Vowel.indexOf(Question).equals(-1))
if(Answer.equals("B"))
{
CorrectAnswer = CorrectAnswer + 1;
}
else if(Consonant.indexOf(Question).equals(-1))
{
if(Answer.equals("A"))
{
CorrectAnswer = CorrectAnswer + 1;
}
else
{
CorrectAnswer = CorrectAnswer + 0;
}
}
}
}
期待你的回复。谢谢!