0

This code in java

boknam [variable] refers to bookname & bokauthor[variable] referes to bookAuthor just not to get confused [ this is not that point here]

Code

                String boknam;
                String bokauthor;
                System.out.print("Enter bookNAme: ");
                boknam = scan.nextLine();
                System.out.println("");
                System.out.print("Enter bookAuthor: ");
                bokauthor = scan.nextLine();

Here I want user to give input bookname & bookauthor but the output is enter image description here I

IT skips to take the input as bookNAme, it is only taking input as bookAuthor, please help will be aprreciated

               System.out.print("Enter bookNAme: ");
                boknam = scan.nextLine();
                System.out.println("");
                System.out.print("Enter bookAuthor: ");
                bokauthor = scan.nextLine();   

boknam = scan.nextLine(); This line here is not working, not asking for input NOTE:- THE VARIABLE IS ALREADY ASSIGNED TO DON'T SAY YOU DIDNT INITIALIZED A STRING boknam

Abdul raheem
  • 135
  • 2
  • 11
  • Does this answer your question? [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – vanshaj Dec 05 '21 at 07:54

1 Answers1

2

Sometimes, we have to clear the buffer after getting integer input. Here, after getting your Choice input, we have to clear the buffer so just add an extra line scan.nextLine() before boknam = scan.nextLine(); and that should work just fine.