当我运行程序100是由数字众说纷纭,但一旦它到达0将出现一条消息,告诉用户说100不能由0Java中,尝试捕获后继续
分我如何获得程序在错误之后继续,并将其余的数字除以100。
这是我当前的代码:
public class testing {
int[] table;
int number;
public testing(int number) {
this.number = number;
table = new int[number];
}
public static void main(String[] args) {
try {
int[] numbers = { 2, 3, 0, 4, 5 };
testing division;
for (int i = 0; i < 5; i++) {
division = new testing(100/numbers[i]);
System.out.println("Answer is " + division.number);
}
} catch (Exception e) {
System.out.println("A number cannot be divided by 0");
}
}
}
请使用提供标准缩进的工具,任何好的IDE都可以。 –