• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with constructors of Long and Float

 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

why doesnt line 1 one causes a runtime exception while line 2 does?
thanks
 
Muhammad Ijaz Ahmed
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the reason is your are using "L" upper case, it should be lower case so try this
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ijaj
this is not the case
for long and float numbers
L or l and F or f do not matter
 
Muhammad Ijaz Ahmed
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Prasad:
Thanks for correction. So does that mean we can't pass string either suffix is l or L. we have to pass numeric string?
 
Henry Wong
author
Marshal
Pie
Posts: 21192
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?


The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.

Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.

Henry
 
kevinn lee
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?


The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.

Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.

Henry

thank you henry

I came across this in a certain mock exam.Are we supposed to know things like this for the exam?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic