This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
So, I think this would typically be an easy problem to solve. I can't seem to figure out what I'm doing wrong, though. An easier way to show how I feel is with this emoticon:
I am practicing with some loops. All of them work except for the last one. My main goal is to output the values of the square-root of 2 (might be wording this wrong, but basically I want: 1, 2, 4, 8, 16, 32, 64, etc) until the value can no longer fit inside of a long data type. I recall hearing the maximum value of a long is 9223372036854775808, but for some reason compiling in cmd (as well as in eclipse and TextPad) tells me it's out of range. Oddly enough, it says it's out of range for an int, even though I'm trying to declare it as a long.
Am I declaring this incorrectly? Am I just completely insane and currently living in an alternate error-filled compiling universe?
Any help would be appreciated!
And most of all, thank you for your time!!
Carpe diem, because every day is worth living to its fullest.
First you are doing this:
long loopControl4 = 1, comparison = 9223372036854775808;
The number constant to the right of the equal sign is an integer, by default, which is why you get the compilation error saying the value doesn't fit into an integer. You have to qualify the constant with an 'L' at the end so Java knows you want a long constant instead of an integer constant:
long loopControl4 = 1, comparison = 9223372036854775808L;
Then, you still get an error saying that 9223372036854775808L is too large to fit into a long, because it is. The largest positive value for long is 9223372036854775807L, you were off by 1.