testiterated.java
来自「Beginning Java 2, SDK 1.4 Edition Exerci」· Java 代码 · 共 30 行
JAVA
30 行
// Chapter 7 Exercise 3
public class TestIterated {
public static void main(String args[]) {
try {
loopy(); // Call the method that will throw the exception.
}
catch(IteratedArithmeticException e) {
System.out.println(e);
}
}
// This method throws an exception - eventually:
static void loopy() throws IteratedArithmeticException {
int iteration; // Iteration counter.
int result; // Stores a result.
int divisor; // Random divisor.
// Loop will continue until an exception is thrown:
for(iteration=0;;iteration++)
try {
divisor = (int)(100*Math.random()); // Generate a random divisor.
result = 1000/divisor; // If we hit zero - bingo!
}
catch(ArithmeticException e) {
throw new IteratedArithmeticException(iteration);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?