I've noticed a weird behavior in Intellij Idea Community Edition run window.
Here is my code
Scanner scanner = new Scanner(System.in);
var list = new ArrayList<Integer>();
String[] arr = scanner.nextLine().split(" ");
for (String number : arr) {
list.add(Integer.parseInt(number));
}
// scanner.nextLine();
int n = Integer.parseInt(scanner.nextLine());
When I run it with input
1 2 4 5
3
It will return empty String ""
on int n = Integer.parseInt(scanner.nextLine());
, unless I uncomment scanner.nextLine()
on line 9. Then it works as intended and returns 3
.
I have tried to run compiled code in a Terminal window and it works just fine without extra scanner.nextLine()
.
I am running it on Zorin OS 16.1, IntelliJ IDEA 2022.1.1 (Community Edition) from flathub.
This behavior does not occur when I try it on my Windows 11 machine.
My question is why does it occur and how to have the same behavior on all machines?
CodePudding user response:
As Thomas Kläger pointed out this is a known bug in Intellij Idea 2022.1.1 . Updating to version 2022.1.2 solved the problem.