While testing on IntelliJ it works fine, output is also fine. Any help?