Почему этот код не выбрасывает ArithmeticException
? Посмотрите:Разделение Java на ноль не бросает исключение ArithmeticException - почему?
public class NewClass {
public static void main(String[] args) {
// TODO code application logic here
double tab[] = {1.2, 3.4, 0.0, 5.6};
try {
for (int i = 0; i < tab.length; i++) {
tab[i] = 1.0/tab[i];
}
} catch (ArithmeticException ae) {
System.out.println("ArithmeticException occured!");
}
}
}
Я понятия не имею!
так, как я могу изменить свой код, чтобы получить ArithmeticException? (Я не хочу менять тип массива на int)? – Katie
Это дублируется http://stackoverflow.com/questions/5291606/why-does-1-0-give-error-but-1-0-0-returns-inf – Seba
'если (вкладка [I ] == 0) throw new ArithmeticException(); '. – assylias