public class Test { static public void main(String s[]){ float f = 10; System.out.println(f/0); } } this program throws ArithmeticException and if I change the denominator to 0.0 works fine. why ? thanks ravee.
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
It works fine as it is(ie. (f/0)). It prints "infinity". Both float and double datatype take care of the divide by zero. Here in the following 2 lines ,implicit conversion takes place ie gets converted to float type. float f = 10; System.out.println(f/0);
Tony Alicea
Desperado
Sheriff
Joined: Jan 30, 2000
Posts: 3219
posted
0
ravee, your observations don't agree with what should happen and which did happened when I tested. Do you know why? Are you sure of what you said?
Tony Alicea Senior Java Web Application Developer, SCPJ2, SCWCD
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.