package com.edu.hrbust.crazy;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class StandardTest {
public static void main(String[]args) {
Scanner inputAnswer = new Scanner(System.in);
int score = 0;
StringBuffer answer = new StringBuffer();
String result = "ABCD";
try {
FileReader inOne=new FileReader("test.txt");
BufferedReader inTwo = new BufferedReader(inOne);
String s = null;
while((s=inTwo.readLine())!= null) {
if(!s.startsWith("*"))
System.out.println(s);
else {
System.out.println("请输入选择的答案(ABCD):");
String str = inputAnswer.nextLine();
try {
char c = str.charAt(0);
answer.append(c);
} catch (StringIndexOutOfBoundsException exp) {
answer.append("*");
}
}
}
inOne.close();
inTwo.close();
} catch (IOException exp) {
for(int i=0;i<result.length();i++) {
if(result.charAt(i)==answer.charAt(i)||result.charAt(i)==(answer.charAt(i)-32))
score++;
}
System.out.println("最后得分:"+score);
}
}
}
主要是报什么样子的异常
不好意思啦!上课去啦刚回来! 报下面这越界异常
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.StringBuffer.charAt(StringBuffer.java:179)
at com.edu.hrbust.crazy.StandardTest.main(StandardTest.java:37)
@望梅止渴: 字符串索引超出界限
java的