Meaningless Drivel is fun!*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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: 3222
    
    5
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
 
Consider Paul's rocket mass heater.
 
subject: Automatic conversion
 
Similar Threads
Mock Exam Quest
Question About equals( ) method
WA #1.....word association
Passed OMG UML Adv. 96.5%
Says cannot reference f before supertype constructor has been called