I am really new to java. I just bought a book that I am going through and there is a puzzle to solve. I have the solution but my output does not match the output the book says it should be. Anyone care to go over this and help explain to me if the book is wrong?
The output should be: %java EchoTestDrive helloooo... helloooo... helloooo... helloooo... 10
But I get 11. What am I doing wrong?
EDIT by mw: Added Code Tags. [ May 03, 2007: Message edited by: marc weber ]
The code you've shown here won't actually compile, because of the line
e1.count = count + 1;
There's no variable "count" in EchoTestDrive.main(), and the compiler will tell you that. If you change this line to
e1.count = e1.count + 1;
it will, indeed, compile, and give the right answer. If you ran a program and got 11, then you must have made this compile by changing something, just not the right thing, and running that changed program.
Thanks, that correction does makes sense. However, I have only gone through the code in my head, I haven't yet compiled anything. My main concern is why do I get 11 when the book says it should be 10. I guess I am trying to follow the logic in my head and can't see how the answer is achieved.
Thanks! This is my first post but already I have learned quite a bit. Not the least of which is the "code" tags. Here is the section that I don't understand. Why doesn't this if statement get processed when x = 3, thus making e2.count = 11?