• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java rule round up #113

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can somebody explain to me why the following code compiles and runs:
double x; x=24.0/0;
The answer says it will compile and run because floating point nummers don't produce a divide-by-zero ArithmeticException. They will give a result which is Not a Number value. But for me it looks like 24.0 is a double and not a floating point number because it has no f attached to it.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A double primitive is also a floating point number. By default, a floating point value is a double. If you append a 'f' after the number, it becomes a float value.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeroen,
Welcome to Javaranch .
Both float(32 bits long) and double(64 bits long) are floating point values (that is both are decimal values) with different ranges. Default floating point value is 'double'.
For example
float f = 12.0, this will give a compile time as error as '12.0' denotes a double value.to make this statement compile we need to modify it as float f = 12.0F.
So the above answer mentioned is right.
reshma
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic