- package cn.itcast_200;
- /**
- * 输出1-200.不能用循环,不能if语句
- *
- * @author Administrator
- * 分析:不让用for循环,就递归嘛,递归和异常解决
- *
- */
- public class Demo {
- public static void main(String[] args) {
- int i = 1;
- printall(i);
- }
- private static void printall(int i) {
- try{
- System.out.print(i+"\t");
- int a = i;
- a = a/(a-200);
- printall(++i);
- }catch(ArithmeticException e){
- System.out.println("输出完毕");
- }
- }
- }
复制代码 |
|