I'm completely new to java and I decided to take a look at the book 'Head first java' which I know a lot of you guys have as well.
Well this is from the first mixed messages section, and here is the code:
The answer of the output is '00 11 21 32 42'
To me this the code is saying
1) X = 0
2) Y = 0
3) While X is less than 5 (which it is always)
4) y (0) = x (0) - y(0) and to me the sum of this is always 0 :S
5)Print out x(0) + blank space + y(0) + blank space
so to me the output should look like this
0 0 0 0 0 0 0 0 0 0 0 0 etc LOL =[
Could someone please explain it to me, because i'm feeling a bit demotivated by not even being able to do the first couple of exercises haha.
FWIW, even with the " - 1", it would have ended...EVENTUALLY.
Integer-type variables have max. and min. values. If you reach the limit and then add/subtract one more (as appropriate), they 'roll over'. So you can see an extremely large positive value suddenly become a very small negative number, and vice versa.
So, you would get to a value of -2,147,483,648, subtract one more and get to a value of 2,147,483,647, which would then end the loop.
Joined: Jun 27, 2011
Thanks very much for the information! I appreciate your help I'm doing a few more now, so If I don't get it, i'll post here.