# George Foreman

Greenhorn
since Oct 23, 2020
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by George Foreman

Christopher Webster wrote:If you really want to practice recursion (without all the Java kruft  ), try The Little Schemer - lots of simple bite-sized exercises to get you thinking in a recursive and functional style, using the Scheme language (a variety of Lisp).  Because Scheme syntax is pretty minimal, it helps to reveal the underlying logical patterns in these exercises.  You'll probably never program in Scheme for real, but the principles are the same in any language.

And if you really want to dig deep, try Structure and Interpretation of Computer Programs (SICP) which is available free online.

Thanks for that little tip. I'll look into that.
3 weeks ago

Campbell Ritchie wrote:Didn't I say yesterday that method would be regarded as cheating?

Well... who's going to say "no" to an offer like that. LOL
3 weeks ago
StringBuilder!!!
3 weeks ago
The program was orginally written by someone else on chegg... I would post a link but you have to pay for a membership. I modified the original code. I'm just doing some recursive problems trying to figure it out.

4 weeks ago

I'm struggling with line 18. So

s is the parameter variable in which substring method acts upon. The first parameter of s.substring has the value e and I'm not so sure about the second parameter. Could someone explain, I'm not sure how this simplifies after each recursive call?

reverseString(...) this is where the recursion begins and substring method takes the entire string and uses it as a parameter for the reverseString method and the method repeats itself from there.
4 weeks ago

salvin francis wrote: I suggest posting your final code here so that it helps others...

This should look a little prettier.
1 month ago

Campbell Ritchie wrote:Have you solved the problem about the two occurrences of the word,"smallest" in line 16? That was my one to go

Well one is a variable and the other is a method name.
1 month ago

Campbell Ritchie wrote:
Two down, one to go.

At the risk of being redundant, so the declaration on line 16 has nothing to do with the declaration on line 24 because of different variable scopes making them different variables. Line 24 declares smallest and lines 26, 28, & 30 initialize smallest, which hints why the errors if line 24 is omitted.

Correct me if I use the wrong terminology. I understand that values 1, 2, 3 are initialized by scanner and value 1, 2, 3 are then passed to parameters on line 22 to a, b, c. When line 16 is executed do value 1, 2, 3 become whatever they were previously initialized on lines 13-15? Is this just sloppy coding because values 1, 2, 3 could just be written as a, b, c from the beginning... but this would neglect the average method, so is it always a good idea to use some third party variables to pass into the parameters so they can be reusable?

I still don't understand the purpose of initializing a variable with a method and it's parameters... or even how that runs. Is that sloppy coding?
1 month ago

Campbell Ritchie wrote:

Campbell Ritchie wrote:
Was the code formatted so badly, or is that how you copied it?

Ill take partial blame for that.

Campbell Ritchie wrote:
You are right to query why they are using floats, which is an error.

Why does it still run?

Campbell Ritchie wrote:
I shall let you guess why the word “smallest“ appears thrice with different meanings. Tell us what you think and we'll see whether we agree.

Well, on line 16 value1,2,3 is being passed to the method parameters on line 22. I'm not sure why on line 16 there is a variable declaration. Line 23 is necessary for the program to run perhaps because they have two different scopes?

Campbell Ritchie wrote:
The above is what I think is the correct solution, because you should use library code whenever possible. If you look at the documentation, you will find that method will handle NaN consistently.

I'll try to keep that in mind... thank you for all of your help.
1 month ago

salvin francis wrote:
Where did you get this program from ? Please QuoteYourSources <-- It's a link

The program came from chegg. You need a subscription to access it. Should I still post the full link?

salvin francis wrote:
Next, what happens when you run this program ?

salvin francis wrote:
If you haven't done it already, I suggest having a look at oracle's tutorial for java. Specifically about methods: https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html
and this: https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html

Will do.
1 month ago

I'm confused by the variables smallest and average. What is there purpose? Why is there a method assigned to them as a value? All information on these mysterious variables is appreciated.
1 month ago