Divide-by-zero using int
int num2 = 1/0;
System.out.println(num2); // occurs ArithmeticException
Output
Exception in thread "main" java.lang.ArithmeticException: / by zero
at TestJavaHack.main(TestJavaHack.java:10)
Divide-by-zero using double
double num1 = 1.0/0.0;
System.out.println(num1); // prints Infinity
if(Double.isInfinite(num1)) {
System.out.println("The value is Double.INFINITY");
}
Output
Infinity
its Double.INFINITY
No comments:
Post a Comment
Note: only a member of this blog may post a comment.