This week's book giveaway is in the Design forum.
We're giving away four copies of Head First Software Architecture: A Learner's Guide to Architectural Thinking and have Raju Gandhi, Mark Richards, Neal Ford on-line!
See this thread for details.

Taylor Street

Greenhorn
+ Follow
since Jul 10, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Taylor Street

I think I answered my own last question. I was missing the point that once the int or factor was assigned x, that is how many zeros it will have prior to being multiplied by y or 10. Thanks so much for all the help. This forum is great!
13 years ago
Pete, thank you so much! It worked! With my additional System out, I am much closer to understanding. The first loop reads: When x was 5 the doStuff method returned a value of 500000. How can that be? "ivar" takes the value of "y" and the value of "y" is 10 and never changes.
13 years ago
Thank you for the reply David. It was very helpful! I have attempted to add some additional code to help me follow along with what is happening as the code runs for learning purposes; however, I can't seem to get it to compile correctly after I added the additional code and System out. What am I doing wrong? Maybe trying to learn the Java Util Logging (JUL) would be better?

13 years ago
This puzzle is tripping me up for some reason. For instance, result = result + obs[x].doStuff(x); Why the need for doStuff(x)? Also, it doesn't give "factor" a value and it seems it should have one? Here is the code and the output for the puzzle:

public class Puzzle4 {
public static void main(String[] args) {
Puzzle4b[] obs = new Puzzle4b[6];
int y = 1;
int x = 0;
int result = 0;
while (x < 6) {
obs[x] = new Puzzle4b();
obs[x].ivar = y;
y = y * 10;
x = x + 1;
}
x = 6;
while ( x > 0 ) {
x = x - 1;
result = result + obs[x].doStuff(x);
}
System.out.println("result " + result);
}
}
class Puzzle4b {
int ivar;
public int doStuff(int factor) {
if (ivar > 100) {
return ivar * factor;
}else{
return ivar * ( 5 - factor );
}
}
}

Output:
%java Puzzle4
result 543345
13 years ago