File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Automatic conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Automatic conversion" Watch "Automatic conversion" New topic

Automatic conversion


Joined: Feb 18, 2000
Posts: 19
public class Test {
static public void main(String s[]){
float f = 10;
this program throws ArithmeticException and if I change the denominator to 0.0 works fine.
why ?
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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;
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
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:
subject: Automatic conversion
It's not a secret anymore!