![]() |
Skipping input.nextLine();
Hello! I have a issue here, and to be honest I have seen this beofre, but I cannot remember how I corrected it. The problem is in this line:
Names[custNum] = input.nextLine(); the problem is that it skips that line.. completely. That is the second input line in the constructor, and is followed by a system.out.println(); line. if you need more ask! Thanks! |
:
the problem is that it skips that lineObviously, that line isn't excuting to skip itself. Post more of the code. |
Quote:
public static void saveBalance() { System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); System.out.print("Please tell me, what is the ID of the customer?"); custNum = input.nextInt(); System.out.println("Thank you!"); System.out.print("Now please tell me this customer's name?(" + custNum + "):"); Names[custNum] = input.nextLine(); System.out.println(" "); System.out.println("Thank You!"); System.out.print("Now please tell me " + Names[custNum] + "'s balance: "); Balance[custNum] = input.nextDouble(); System.out.println("-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"); control(); } |
Also, further down in the program, the code skips the very same type line. (A input.nextLine) And I do remeber this is class being a topic my teacher covered. I just don't remember what he said.. ;)
|
Read the forum's rules/FAQ. You can learn about code tags there, and discover other things regarding the community which you wish to use as a resource. It's only the neighborly thing to do.
|
Ok, first off a couple things:
#1 - put your code in code tags if you want anyone to help. (honestly) #2- I'm looking at this page: http://www.cs.wisc.edu/~cs302/io/JavaIO_Scanner.html Are you sure your defining custNum properly? I think when you get the user input, its going to be a string. You will need to convert it. Also where is it defined? Im not big on Java, but hope this helped. Last thing, are you getting any errors when you execute the code? |
I am sorry. I come from a forum with no such rules. Anyways here is the code again, and I put a comment in where it skipps. Also, if I output the custNum var (declared and initialized above this) just after where it is inputted, it does come out correctly. And no, I get no errors! Thanks again, sorry about before!
:
public static void saveBalance() |
What class is the 'input' variable an instance of?
|
Quote:
:
public static Scanner input = new Scanner(System.in); |
Check out the documentation for the Scanner class. According to the docs, the nextLine() function:
Quote:
|
| All times are GMT -5. The time now is 7:59 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC