java怎么退出所有递归

public class Main { 
 public static void main(String args[]) { 
 System.out.println("start!"); 
 try { 
 find(0); 
 } catch (StopMsgException e) { 
 System.out.println(e); 
 } 
 System.out.println("done!"); 
 } 
  
 private static void find(int level) { 
  
 if (level > 10) { 
 // 跳出 
 throw new StopMsgException(); 
 } 
 // 执行操作 
 System.out.println(level); 
 // 递归 
 find(level + 1); 
 } 
  
 static class StopMsgException extends RuntimeException { 
 } 
}  

猜你喜欢

转载自oywl2008.iteye.com/blog/2076817
今日推荐