How to read input with multiple lines in Java

后端 未结 10 1163
名媛妹妹
名媛妹妹 2020-12-05 02:48

Our professor is making us do some basic programming with Java, he gave a website and everything to register and submit our questions, for today I need to do this one exampl

10条回答
  •  悲&欢浪女
    2020-12-05 03:55

    Use BufferedReader, you can make it read from standard input like this:

    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    String line;
    
    while ((line = stdin.readLine()) != null && line.length()!= 0) {
        String[] input = line.split(" ");
        if (input.length == 2) {
            System.out.println(calculateAnswer(input[0], input[1]));
        }
    }
    

提交回复
热议问题