Win a copy of AWS Security this week in the Cloud/Virtualization forum!

fred rosenberger

lowercase baba
+ Follow
since Oct 02, 2003
fred likes ...
Chrome Java Linux
St. Louis
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 Green check

Recent posts by fred rosenberger

Hanna Roberts wrote:but wouldnt that return multiple values to the main?

No.  Main only calls doMagic2 once, and gets a single value from it.

However, when that doMagic2 runs, it makes a call to doMagic2.  so now, your main is waiting for the first doMagic2 to return a value, but before that happens, that call is waiting for another version of doMagic2 to return...and so on.  You can think of it as being similar to a set of Russian nesting dolls...Main can only see the outermost, biggest one.  The biggest one can only see the one directly under it, and has no clue how many more there might be.  
1 day ago
a method should really do one thing, and one thing only.  Here, you have a method that is reading input, figuring out the largest, figuring out the smallest, printing output, and possibly more.

break this up into many smaller, simpler methods.  Have a single method that asks for input, and returns the value.
have a single method that returns the larger of two values.
Have a single method that returns the smaller of two values.

and so on. Build up your code a tiny piece at a time, and compile and test it ten times more often than you think you should.
1 week ago
and forget about java for a minute...If I put a whole bunch of pizzas on a table, how would you, personally, identify the "maximum" one?  think about it, step by step, in english.  think about what you'd need to do, what you'd need to remember, and what you need to check at each step...
1 week ago

Campbell Ritchie wrote:By the way: what does the === operator do?

Oh Campbell....that seems like something a quick google search would tell you.  ;-)

If i recall, it's a strictly equals.  in some languages, an int of 10 would be equal to a string of "10", but not strictly equal, due to different types.
2 weeks ago

Tim Holloway wrote: if it's Monday, subtract 3 days from it, else subtract 1 day from it.

You may need another condition here if the code can run on Sundays...
3 weeks ago
as i get older, i find it harder and harder to stay focused.  My mind tends to drift dog is barking. better go see what she wants.
3 weeks ago
I didn't see this mentioned, but once a cmd window is open, the environment variable for THAT window are set.  there probably are ways to update it within an open window, but it's probably easier to close the current one and open a new.
3 weeks ago
Why don't you tell us what you think is going on.  You'll learn more if you try and figure it out yourself - and by that, i mean actually put it down in words somewhere.  Preferably in a post in this thread.

Go through it line by line, writing out what each variable is/gets set to, what steps the code takes, and why.

Once you do that, we can correct any misconceptions.  But a lot of the time, when you have to write it out, you see what you are doing/thinking wrong.
1 month ago
well, then fix that error.

In all seriousness, we cannot help you if you don't show us the code that is giving the error.  Also, tell us what EXACTLY the error says.  You should try and make is as easy as possible for people to help you if you want help.  
1 month ago

Fudgie Braun wrote:So you're saying I need to put the input text file into an array?
But before I put that into an array, I need to change each line into a string then put all those into the array?

No.  You asked what parsing was, and I was trying to explain that, using your problem as an example.

What you need to do is figure out your algorithm.  Forget about java, arrays, parsing...just think in English (or whatever your preferred natural language is...).  start describing what you need to do, step by step.  then go back and refine each step, making them more detailed and explicit.  For example:

open the file
as long as there are more lines in the file
 read a line
 look at each number in the line
 add 1 to a counter for each number found on that line

When the steps are clear enough, start coding.  Code the smallest amount you can, then compile, test and debug.  I generally go 2-3 lines AT MOST before i recompile.  So my first go would be simply trying to open the file, then close it, without getting an error.  I would not try reading it, printing it, or doing anything else...literally just open and close without error.

THEN I'd go back and try reading a line and printing it.
THEN i'd go back and try reading each line, and printing each, one after the other.
THEN I"d go back and try adding anotehr tiny piece...
1 month ago
Parsing simply means reading in the data, and figuring out what parts are what.  Any modern language will have built-in tools to help you do this.  

One way you could try would be to read in the file a line at a time and save it to a string.  Then you can use various String methods to break apart that string into the pieces. In your case, you're going to break it apart by the dashes (and discarding them).  You'd be left with an array of six elements.

You could convert each to an integer type, or just continue using them as strings.

1 month ago
it's been a while since I did any C coding...over 15 years, at least, so I may not be 100% correct here...

I believe C is pass-by-value.  so, if you just had "scanf("%d", hourlyWage);", you'd be sending in a value 0 (assuming varibles get C you might just get whatever junk was already in that memory space).  

Instead, you want to pass the address of what hourlyWage points to, so that inside the scanf method, it can set the value.  That way, when the funtion returns, your variable will now hold the correct value.

In your second example. you're simply setting it directly, so you don't need the ampersand.
1 month ago
This is the right forum.  
1 month ago
You don't necessarily need to convert them into integers...After all you may someday want to parse a file with input like:


etc.  in other words, the fact that they look like integers now may not matter.  What you are really looking for is repeated 2-character patterns.  If you know they will always an only ever be 2-digit integers, then you can maybe take a few shortcuts.  You'd know they can only be 0-99.  That suggests you might be able to use an array with 100 elements to hold your count of each value found.

Now....Why 49?  is it because it's the first element in the first row, or is there some other criteria?  I don't think it's because it appears the most often, because I see 40 in there three times.

1 month ago

Campbell Ritchie wrote:Won't people recognise and follow a leader automatically?

I think you overestimate people...
1 month ago