• Post Reply Bookmark Topic Watch Topic
  • New Topic

dividing by zero not throwing exception  RSS feed

 
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question : did not show output ?
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dividing 0 by 9 does not throw any exceptions.
 
Saad Zahoor
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put

int x = 9 ;
int y = 0 ;

so you will get an exception.

if you have

float x = 9 ;
float y = 0 ;

you will not get an exception: you'll get Infinity.

the same for double.

 
Master Rancher
Posts: 2045
75
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Dana,

you have made quite some good replies concerning these nasty OCAJP like questions. So enjoy a well-deserved cow!
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for a cow Piet!!!

I have a cow. :-)

Yet I am learning for OCA 7 exam.

 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Today I found that exists NaN pentru float and double.



 
Marshal
Posts: 56610
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you found out that Java® supports three kinds of built‑in arithmetic?
  • 1: Integer arithmetic, e.g. with ints or BigInteger.
  • 2: Floating point binary arithmetic, i.e. doubles and floats.
  • 3: Fixed point decimal arithmetic with BigDecimal.
  • Integer arithmetic only suffers one potential error, though it has all sorts of peculiar rules, e.g. about division and about mixing different types. Integer arithmetic and decimal arithmetic are absolutely accurate unless that one potential error occurs. Decimal arithmetic also has some peculiar rules about division. Floating point arithmetic is almost always imprecise, and it has other peculiar rules, including rules about division by 0. It follows IEEE754. NaN is probably the strangest part of IEEE754.
    You can find more details in the Java® Language Specification (beware: some bits will be difficult to read), starting with this section. Keep reading until you reach the bitwise OR operator, and see whether you are still awake.
     
    Dana Ucaed
    Ranch Hand
    Posts: 406
    6
    Netbeans IDE Oracle Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Campbell. for your replay.

    NaN there is and in JavaScriot.


     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!