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");
}
}
}
All calculations that involve float are evaluated to NaN, as specified in IEEE 754 standard. Only integer "divide by zero" will throw ArithmeticException.
2016 Apr 25, 7:12:34 PM
Ввійдіть щоб вподобати
Ввійдіть щоб прокоментувати