• Post Reply Bookmark Topic Watch Topic
  • New Topic

why parseInt("99", 8) throws a NumberFormatException?  RSS feed

 
Alex Shin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In JAVA doc, there is an example of int java.lang.Integer.parseInt(String s, int radix) throws NumberFormatException:

parseInt("99", 8) throws a NumberFormatException

Could anyone please explain why parseInt("99", 8) will throw a NumberFormatException? I don't understand this example.

Thank you!
 
Stephan van Hulst
Saloon Keeper
Posts: 7817
142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Have you read in the documentation what the second parameter does?
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, a radix of eight is an octal number right?  Is a "9" a valid digit for an octal number?

Henry
 
Alex Shin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when I using programmer calculator, 99 in octal number equals 143, why is that??
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alex Mma wrote:But when I using programmer calculator, 99 in octal number equals 143, why is that??


A 99 in decimal is equal to 143 in octal... but that is not what you are asking the method to return. You are asking the method to return the number in decimal that is equal to 99 in octal.

What number should be returned? ... meaning what number in decimal is equal to 99 in octal?

Henry
 
Norm Radder
Ranch Foreman
Posts: 2240
28
 
Alex Shin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!!
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
 
Alex Shin
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will be careful with the policy next time
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!