Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.

Carey Brown

+ Follow
since Nov 19, 2001
Carey likes ...
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
Forum Moderator
Carey Brown currently moderates these forums:
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Carey Brown

Ah, line 31 change made all the difference. I still had it as the OP's nextLine() vs your nextInt(). Thanks for the post.
17 hours ago

Campbell Ritchie wrote:

Carey Brown wrote:. . . I think I'm following your suggestion here, . . .

Afraid you aren't. Why is he using Strings instead of booleans in the first place?
You are also not calling nextLine() before line 3. That will throw all your lines out of sequence, and will cause all sorts of problems. You will probably be lucky and get an exception.

Ok Cambell. I'm left to guess at your intent because your words are not  precise enough. So, this? No. It doesn't work either, whereas my post a few back did work. Can you show me?
And the OP is generating a report so whether it is paid in part by insurance or not needs to end up being a String. Of course "true" and "false" are lousy Strings for a report, "Y" or "N" (or something similar) would be more appropriate.
19 hours ago
Note that you are incrementing "i" twice.
22 hours ago

Campbell Ritchie wrote:Suggestion to avoid the exception: stop reading when there is no more text. To do that, replace while (myScanner.hasNextLine())... with while (myScanner.hasNext())... I think deleting four letters will obviate the exception good and proper.

I added line 44 prior to running this. I think I'm following your suggestion here, but it doesn't work.
23 hours ago
THIS discussion was posted yesterday. It involved reading a record from a file laid out as 5 separate lines of input.  After each non-nextLine() call the OP put a call in to nextLine(). So, the very last item in a record was a double with a call to nextDouble() followed by a call to nextLine(). This worked for all the records except the last one because there was no new-line character following the last double, so it threw a NoSuchElementException.

So here we have another case where always adding a call to nextLine() causes a failure.
1 day ago
This is why I hate Scanner. It's a bear to debug. The output file should have given you a little clue that everything was ok up until reading the last record.
1 day ago
1 day ago
It read up to X-ray ok but when you try to read the last record you do not have a nextLine().
1 day ago
1 day ago

Chad Dunlosky wrote:Everything worked like it should, but I think I'll use Eclipse to better practice java, even though there's nothing wrong with the command prompt, all guides I read have Eclipse as recommended.

Eclipse is an excellent tool but I caution against it for the short term. If you are just starting out with HelloWorld, using the command line will help you understand how the organization of a Java project works. Eclipse, of course, helps with this, but you may have trouble understanding errors in Eclipse without some of this background knowledge. Eclipse also has its own learning curve.
1 day ago
What input did you give it?
1 day ago
Are you reading from a file or the keyboard? Can we see the line(s) where you create inputScanner?
1 day ago
compiles your java file which should result in HelloWorld.class file being created.
will run the .class file.
1 day ago
"subjects" and "subjectlist" aren't being used.
1 day ago
It would really help us to help you. One way would be to provide properly formatted code. If you show effort then we are more likely to contribute. It would also help if you provided a stand-alone, subset of your project that we can compile and run (this would probably benefit you as well).

Here's an example, though it doesn't entirely compile. There are some missing pieces that I can't guess at.

Notice you have "i++" twice.
1 day ago