Ask coding questions

← Back to all posts
No operation
Bunnytoes (231)

It works fine if it has set double values, but when you can pick it I can't get past System.out.println("Enter the operation"); it closes after than and returns 0 (which is what it does if no other option is chosen) please help

Answered by fuzzyastrocat (1896) [earned 5 cycles]
View Answer
Comments
hotnewtop
fuzzyastrocat (1896)

I'm not a Java expert, so I can't tell you exactly why this is the case, but change

to

It might be because the last sc.nextDouble() doesn't catch the final newline in that input (you type the number and then a newline, but sc.nextDouble() might not catch that), so it "bleeds over" into the next input and thus causes the result of sc.nextLine() to be empty?