Pages

Tuesday, June 16, 2015

Java - Division by Floating Zero

An amazing result of Java Program on Division by 0.0

 public class Fruits {  
   public static void main(String args[])  
   {  
     int numOranges=5;  
     int numApples=10;  
     double averageFruit=0.0;  
     double fruitTypes=0.0;  
     averageFruit=(numOranges+numApples)/fruitTypes;  
     System.out.println("Average fruit is "+averageFruit);  
   }  
 }  
 Output : Average fruit is Infinity  


Infinity means a positive but effectively infinite result that is greater than the largest number that can be stored in double

No comments:

Post a Comment