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