如何在字符串中存储用户键盘输入中的每个答案?
for (int i = 0; i < 3; i++){
System.out.println("insert the answer ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String userAnswer[] = new String[3];
try {
userAnswer[i] = br.readLine();
} catch (IOException ioe) {
System.out.println("IO error ,trying to read your answer");
System.exit(1);
}
int count =0;
count++;
String we[] = new String[3];
System.out.println("the answer is " + userAnswer);
System.out.println("the answer is " + count);
}
答案 0 :(得分:3)
使用Scanner。
Scanner scanner = new Scanner(System.in);
List<String> answers = new ArrayList<String>();
for( int i = 0; i < 3; i++ )
{
answers.add(scanner.nextLine());
}