This is a question related to the Java buffered reader output.

Asked 2 years ago, Updated 2 years ago, 25 views

To solve Baekjun's problem, I wrote the following code to find out about bufferedReader.

    int C;

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    C = Integer.parseInt(br.readLine());
    System.out.println();

    for(int i = 0; i < C; i++) {
        String brr = br.readLine();
        System.out.println(brr);
    }

Input 5

5 50 50 70 80 100

7 100 95 90 80 70 60 50

3 70 90 80

3 70 90 81

9 100 99 98 97 96 95 94 93 91

Output

5 50 50 70 80 100

7 100 95 90 80 70 60 50

3 70 90 80

3 70 90 81

9100 998 996 95 9391 //This guy comes out without input and must be pressed to output

The output is up to 370 9081 and you enter the enter The last line was printed I was wondering if the enter value (\n) was needed, so even if I added println, it was the same I wonder why I have to put the enter value in that way to print the last line.

java

2022-09-20 10:27

1 Answers

If there is a problem with buffer-related processing, you can usually flush it.

flush - Apply contents inside buffer

See also

There is no flush output and no flush input, so I think I need to use close


2022-09-20 10:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.