• 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

10/0 is equal to 10/0.0???

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
plz look at the code
int a=10/0;
if i want to perform it then there will be a run time error. it is fine.
but in
double a=10/0.0 there will not be any run time error and the answer will be infinity. why?
please look at another problem

int x=012;
if ( x==10) { System.out.println("if part"); }
else{System.out.println("else part");}
it is printing "if part" why?
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ritwik roy:
plz look at the code
int a=10/0;
if i want to perform it then there will be a run time error. it is fine.
but in
double a=10/0.0 there will not be any run time error and the answer will be infinity. why?
please look at another problem

int x=012;
if ( x==10) { System.out.println("if part"); }
else{System.out.println("else part");}
it is printing "if part" why?




A java.lang.ArithmeticException will be thrown if there is an integer division by zero. However,

- a positive float/double division by zero will result in
a POSITIVE_INFINITY

- a negative float/double division by zero will result in
a NEGATIVE_INFINITY

In you example, 10 will be promoted to float so the result is infinity.

Hope this helps...
 
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
012 (octal) is equal 10 (decimal)
Infinity is a special constant value :-
- any positive number divide 0.0 is Infinity.
- any negative number divide 0.0 is -Infinity.
- 0/0.0 is NaN
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

int a=10/0;
if i want to perform it then there will be a run time error. it is fine.
but in
double a=10/0.0 there will not be any run time error and the answer will be infinity. why?
please look at another problem

int x=012;
if ( x==10) { System.out.println("if part"); }
else{System.out.println("else part");}
it is printing "if part" why?



In the expresion a=10/0.0 denominator is a double, So 10 is also promoted to double and the overloaded division operator for double is invoked. / operator for double returns Double.Infinity when denominator is 0.0.

interger literals that start with 0 are interpreted as octal values. So decimal equalent of 012 will be 2+8 ie 10.

integer values that start with 0x are interpreted as hexadecimal values.

Hope I have answered your queries.

Try executing a= 10/-0.0;

Thanks
Shyam Ramineni
 
ritwik roy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks u all.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic