What is the difference between this?

hi all,

I just want to know difference between following statements. please help me out.

1. double d = 10.0 / 0;

2. double d = 10/ 0;

the first one wil give result "Infinity"

and the second create / by zero exception.

why it is like that...

again double d = (double)10/ 0 will give result "infinity".

thanks in advance.

Phoeniox

[390 byte] By [Phoenioxa] at [2007-11-27 5:11:32]
# 1

Notice the right side (only) of the operations; never mind about the process after the arithmetic operation:

1. because you're dividing two doubles, you get infinity

2. because you're dividing two integers, you get arithmetic exception.

This is the behavior when you divide double/integer with zero; all these rules are set in Java Language Specifications.

eadelarosaa at 2007-7-12 10:31:56 > top of Java-index,Java Essentials,Java Programming...
# 2
From Wiki:In computer programming, integer division by zero may cause a program to terminate or, as in the case of floating point numbers, may result in a special not-a-number value.In Java integer division by zero definately terminates the program.
floundera at 2007-7-12 10:31:56 > top of Java-index,Java Essentials,Java Programming...
# 3
Hi all,Thanks for both of you.... regardsPhoeniox
Phoenioxa at 2007-7-12 10:31:56 > top of Java-index,Java Essentials,Java Programming...