All things are lawful, but not all things are profitable.
bob john wrote:
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Problem: Whenever you use a 'next....' method, you should use its associated 'hasNext...' method.
What do you think that might be?
Winston
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:You should only call the next method if the thing you are iterating through actually has a next item to get.
Also, i would suggest that variables like "om" and "str" are poor choices for variable names. Your not IMing someone. You have a full keyboard. Use descriptive names so you know what the variable represents.
Problem: Whenever you use a 'next....' method, you should use its associated 'hasNext...' method.
All things are lawful, but not all things are profitable.
bob john wrote:
fred rosenberger wrote:Also, i would suggest that variables like "om" and "str" are poor choices for variable names. Your not IMing someone. You have a full keyboard. Use descriptive names so you know what the variable represents.
Yet I dont write projects, nor doing some kind of homewok plan.
Im learning and writing short codes. They are common and generic, in overall expired of imagination.
All things are lawful, but not all things are profitable.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Okay, what's the problem now? You're having trouble with a try/catch? Can you post the code?
bob john wrote:
Knute Snortum wrote:Okay, what's the problem now? You're having trouble with a try/catch? Can you post the code?
http://docs.oracle.com/javase/tutorial/essential/io/file.html
I have not learned it yet.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:But you're using File() just fine in your program.
On tree grows fruit: apples 11
In the shop lays fruit: bananas 6
Outside grows fruit: berries 5
apples 11
bananas 6
berries 5
bob john wrote:If I run the program, console will display:
On tree grows fruit: apples 11
....
What I want to get? This is what I want to get in console, without modify text file:
apples 11
...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
bob john (assumed via image) wrote:I need some kind of arguments / parameters. To make scanner scan only desired part of text file.
Knute Snortum wrote:You could just do a split on ":" after reading a line.
Campbell Ritchie wrote:Or find the index of ":" and take a substring.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
Knute Snortum wrote:You could just do a split on ":" after reading a line.
Campbell Ritchie wrote:Or find the index of ":" and take a substring.
Carey Brown wrote:split() returns a result that you are throwing away. I suggest reading up on split() in the API javadocs.
http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-
Carey Brown wrote:What does this return?
public String[] split(String regex)
In your case the regex would be ": ". This will split the string when it encounters a colon followed by a space.
Sergiu Dobozi wrote:Here is a simple code that I wrote in about ten minutes (I know it's a lot, but I'm still a beginner). It doesn't solve your problem, but if you understand it, and you can apply the logic, I'm sure you can figure out the solution to your problem.
Consider Paul's rocket mass heater. |