Scanner scanner = new Scanner(System.in, System.out.charset());
This solution works with Java 18+. This works both in Eclipse with default settings and in Windows command prompt having code page 852. Checking the code page:
chcp
Changing it to 852:
chcp 852
Thanks for everyone who helped reaching the solution!