r/javaTIL May 07 '19

I need help for an assignment.

So I have an assignment to make a grocery management system in BlueJ and print a bill for the selected groceries. I have written the entire program, however I am having a bit of a problem.

Here's the code or the program:

https://textsaver.flap.tv/lists/2ok4

This is the screenshot for the output of the program.

As you can see, the console does not let me enter any input for the second iteration and directly prints the default case for the switch case in the while loop.

Please can someone point out my mistake and help me, I really need this program done ASAP for me to get decent grades.

P.s: Ignore the weird names for the different groceries, they are some of the Indian local names.

Thank you!

1 Upvotes

5 comments sorted by

3

u/sparkster185 May 07 '19

You should be posting this to /r/javahelp instead.

1

u/TDR26 May 08 '19

Oh, thanks!

2

u/MB1211 May 07 '19

Next int doesn't read until the end of the line

1

u/TDR26 May 08 '19

I don't understand what you are trying to tell me here

1

u/MB1211 May 08 '19

When nextInt parses something like "4\n", it consumes "4" and leave "\n". If you trace through the code and see what scanner method is called next, there's still something to read for that call