This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
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 Elasticsearch in Action this week in the Big Data 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: 3222
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