Java interger with leading zero

View previous topic View next topic Go down

Java Java interger with leading zero

Post by BIT0102-Mohaimin on Mon Sep 12, 2011 1:48 pm

I was asked several times that why java integers with leading zero prints WEIRD results! I have found the answer now.

Actually, an integer literal with leading zero is considered as octal number. Therefore:

Code:
int i = 040 // is 32
int j = 011 // is 9 in
int k = 019 // is compilation error because '9' is not a valid octal digit
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: Java interger with leading zero

Post by BIT0122-Amit on Mon Sep 12, 2011 2:54 pm

Let me guess. Juniors asked it? Very Happy

_________________________________________________________________
Adminship / Moderatorship is not about power, it is about Responsibility.

|About me|My Blog|
avatar
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

View user profile http://iitdu.forumsmotion.com

Back to top Go down

Java Re: Java interger with leading zero

Post by BIT0102-Mohaimin on Mon Sep 12, 2011 2:57 pm

BIT0122-Amit wrote:Let me guess. Juniors asked it? Very Happy
Yeah, I could not answer.
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Java Re: Java interger with leading zero

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum