The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Campbell Ritchie wrote:No, you can write an int literal up to 10 digits. And it does not prevent overflow. You can use any decimal number between 0 and 2147483648 inclusive, and (apart from 0) they are all positive.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:That’s what everybody thinks, but if you look in the JLS link I posted earlier, you find the minus sign never forms part of an integer literal.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Campbell Ritchie wrote:No, you can write an int literal up to 10 digits. And it does not prevent overflow. You can use any decimal number between 0 and 2147483648 inclusive, and (apart from 0) they are all positive. What can you do with the largest value? I shall let the Java Language Specification answer that.
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
naved momin wrote:
Campbell Ritchie wrote:No, you can write an int literal up to 10 digits. And it does not prevent overflow. You can use any decimal number between 0 and 2147483648 inclusive, and (apart from 0) they are all positive. What can you do with the largest value? I shall let the Java Language Specification answer that.
Soory, but i tried one more time in netbeans and it is actually not allowing me to assign value more than 9 digits to a variable of type int.
Matthew Brown wrote:It works in Netbeans when I try it, as long as the 10-digit number is no greater than 2147483647. Which number are you trying to assign?
naved momin wrote:but dont you think
int i = 2147483647 + 2147483647 // will cause a overflow right ?
but why doesn't java gives an error for that , why it runs and gives answer as -2 ?
The JLS page I quoted earlier says 0...2147483648. But one particular value (2147483648) has to have certain treatment. When you see what the JLS says that particular treatment is, you will think it is obvious.Winston Gutkowski wrote: . . . the upper limit is 2147483647 . . .
Winston
The largest decimal literal of type int is 2147483648 (2^31).
All decimal literals from 0 to 2147483647 may appear anywhere an int literal may appear.
It is a compile-time error if a decimal literal of type int is larger than 2147483648 (231), or if the decimal literal 2147483648 appears anywhere other than as the operand of the unary minus operator (§15.15.4).
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:I think the problem here is how it's worded.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here