My Java code works with one input line, but I get unexpected results when the task provides several lines. I’m not sure whether the problem is my input handling or the way I process the data.
I’m currently working on a beginner Java task that requires reading several values from the console and processing them in order. With a single test case, my program gives the expected result, but with 3–5 lines of input, the output becomes incorrect.
For example, I’m using BufferedReader and readLine(), and I’ve checked the main logic several times. I also tried adding a loop, but I’m not sure where the input-reading logic should stop.
What is the best way to determine whether the error comes from the input handling or from the processing logic? I’d appreciate an explanation of the approach rather than just a corrected solution, so I can apply it to similar CodeGym tasks.
Drift Hunters
eliradelorca
Level 1
Java Input Works Once, But Fails When the Task Has Multiple Lines
New
Comments
- Popular
- New
- Old
You must be signed in to leave a comment
This page doesn't have any comments yet