Sjaak Hendriks wrote:
My question is why would the author in the book have the int there if it gives you an error is this due the fact that at the time the book was written java 5 was the latest and now 7 is or am I doing something wrong?
If you define x in an outer scope you cannot define x again in an inner scope. Then the definitions will clash. It's impossible to know which x you're referring to so the compiler will complain.
You can resolve it by not redefining x in the inner scope as you did. Then there's just the x in the outer scope and the compiler will know what x you're talking about. You can also simply use different names. For example x in the outer scope and i in the inner.
---
The reason the book got it wrong I guess is a typo that didn't get corrected. Maybe it is in later editions of your book.
It's quite common. Don't trust your life with what you read in books. And not with what you read at Java sites either.