Sunday, 8 December 2013

Infinity Logic in java Without Exception.

It is normal when we divide a integer number by 0 we get arithmetic exception in java . But you will be surprised to see that the following program does not throw exception rather prints Infinity .

Please have a look at the following code and the corresponding output.

public class TestInfinity {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
float f = 10.0f;
float g = 0.0f;
float z = f/g;
System.out.println(z);
}

}


No comments:

Post a Comment