Answer the question
In order to leave comments, you need to log in
Can't figure out why the last exception works?
public class Test {
public static void main(String[] args) {
int myInt = 0;
float myFloat = 0;
try {
float result = myFloat / myFloat;
} catch (RuntimeException re) {
System.out.println("Exception 1");
}
try {
float result = myFloat / myInt;
} catch (RuntimeException re) {
System.out.println("Exception 2");
}
try {
float result = myInt / myFloat;
} catch (RuntimeException re) {
System.out.println("Exception 3");
}
try {
float result = myInt / myInt;
} catch (RuntimeException re) {
System.out.println("Exception 4");
}
}
}
Answer the question
In order to leave comments, you need to log in
Floating point numbers follow the IEEE-754 standard.
If v > 0 and h == 0, then v/h == INFINITY. It is guaranteed that INFINITY > 0.5.
If v < 0 and h == 0, then v/h == -INFINITY. For him -INFINITY < 0.5.
If v == 0 and h == 0, then v/h == NaN. For him, any comparison, EMNIP, returns false.
INFINITY -- infinity, its type is double/float
https://en.wikipedia.org/wiki/Division_by_zero#In_...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question