开发者

How can I store user input in Strings? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its curren开发者_开发知识库t form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

How can I store each answer from a user's keyboard input in Strings?

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);
}


Use Scanner.

Scanner scanner = new Scanner(System.in);
List<String> answers = new ArrayList<String>();
for( int i = 0; i < 3; i++ )
{
   answers.add(scanner.nextLine());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜