File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Automatic conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Automatic conversion" Watch "Automatic conversion" New topic
Author

Automatic conversion

ravee
Greenhorn

Joined: Feb 18, 2000
Posts: 19
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
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
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.
 
subject: Automatic conversion
 
Similar Threads
Passed OMG UML Adv. 96.5%
Mock Exam Quest
Says cannot reference f before supertype constructor has been called
WA #1.....word association
Question About equals( ) method