After developing for so long in Java, today only I realize that we can actually do divide by zero in Java and does not get runtime exception. I think so far, this is the only language I can see executing divide by zero and show infinity as a result. Most runtime will throw error whenever it encounter divides by zero. This shows that I still lack a lot of basic Java knowledge. Must improve myself more and not let my skills be rusty. To allow divide by zero, zero literal you use should be in double.
public class TestDivideByZero{
public static void main(String[] args){
System.out.println("This will show as infinity : " + 100/0.0);
System.out.println("The following will throw runtime exception : ");
System.out.println("Exception :" + 100/0);
}
}


0 comments:
Post a Comment