Sorry, didn't notice you are new. Welcome.
Hello. Please get your name into the right format before somebody notices.
I have tried your code or something similar, and I did NOT get the result you described.
You would have thought that when you start with wheel 0 that the numberOfWheels++ puts your details into wheels[1]. But it doesn't. It puts the details where they belong, in wheels[0].
Try it: Have 4 wheels. Set your first wheel to "Dunlop 14," the second to "Pirelli 15," the third to "Goodyear 16," and the fourth to "Continental 17."
Print them out using an old-fashioned for loop, not a for-each loop:-
It will print
Number: 0, Make: Dunlop, Size, 14
Number: 1, Make: Pirelli, Size, 15
Number: 2, Make: Goodyear, Size, 16
Number: 3, Make: Continental, Size, 17
Why?
If you look here on the
java tutorial, you will find an operator precedence chart. The very top row contains the two unary postfix operators, something++ and something--, so they have the very top precedence, but you will find on
this page that the postfix operator "evaluates to the value of op before it was [incremented/decremented]."
What that means, is that the something++ changes your something, but the "before" value is used.
Another way to look at it (not accurate): Imagine that although your something++ operator has a high precedence, it has a delay in its execution, until after the statement has been finished with.
Or another way: keep your something++ on a line all on its own if you get confused.
CR
[ May 03, 2006: Message edited by: Campbell Ritchie ]