![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 14
Rep Power: 0
![]() |
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 elder newb. |
|
|
|
|
|
#2 |
|
Expert Programmer
|
the problem is that it skips that line Obviously, that line isn't excuting to skip itself. Post more of the code. |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Mar 2005
Posts: 14
Rep Power: 0
![]() |
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(); }
__________________
The elder newb. |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2005
Posts: 14
Rep Power: 0
![]() |
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..
![]()
__________________
The elder newb. |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#6 |
|
Expert Programmer
|
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? |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Mar 2005
Posts: 14
Rep Power: 0
![]() |
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()
{
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(); //<----- Skips This!!
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();
}
__________________
The elder newb. |
|
|
|
|
|
#8 |
|
Expert Programmer
|
What class is the 'input' variable an instance of?
|
|
|
|
|
|
#9 | |
|
Newbie
Join Date: Mar 2005
Posts: 14
Rep Power: 0
![]() |
Quote:
public static Scanner input = new Scanner(System.in);
__________________
The elder newb. |
|
|
|
|
|
|
#10 | |
|
Expert Programmer
|
Check out the documentation for the Scanner class. According to the docs, the nextLine() function:
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|