您的位置:首页
递归
2016-06-09 16:21
447 查看
/*
* 递归:方法定义中调用方法本身的现象
*
* 方法的嵌套
* Math.max(Math.max(a,b),c)
*
* public void show(int n){
* if(n<=0){
* System.exit(0);
* }
* System.out.println(n);
* show(--n);
* }
*
* 注意事项:
* A:递归一定要有出口,否则就是死递归
* B: 递归的次数不能太多,否则内存溢出
* C:构造方法不允许递归调用
*/
案例1:
View Code
* 递归:方法定义中调用方法本身的现象
*
* 方法的嵌套
* Math.max(Math.max(a,b),c)
*
* public void show(int n){
* if(n<=0){
* System.exit(0);
* }
* System.out.println(n);
* show(--n);
* }
*
* 注意事项:
* A:递归一定要有出口,否则就是死递归
* B: 递归的次数不能太多,否则内存溢出
* C:构造方法不允许递归调用
*/
案例1:
package com.digui.gz_02; import java.io.File; /* * 递归删除带内容的目录 */ public class DiGuiDemo4 { public static void main(String[] args) { File file=new File("C:\\Users\\Administrator.PMIMP83HWNIKWOV\\Desktop\\suibianwanwan"); removeFile(file); } public static void removeFile(File file){ File[] files=file.listFiles(); for(File f:files){ if(f.isFile()){ f.delete(); System.out.println("文件------"+f.getName()+"--------删除"); }else{ removeFile(f); } } System.out.println("文件夹------"+file.getName()+"--------删除"); file.delete(); } }
View Code
相关文章推荐
- 《用tcp/ip进行网际互联》第6章 网际协议:无连接数据报交付
- hdu 最短路径
- sqlplus执行SQL文件
- Compare Version Numbers
- atom无法安装插件的解决方法之一
- SSH开发问题——attempt to create saveOrUpdate event with null entity
- Dns & IPAddress
- SQL 2008 视频总结(三)
- LeetCode-37.Sudoku Solver
- java.io.File
- Codeforces Round #328 (Div. 2) D. Super M
- Lightoj 1005 Rooks(DP)
- 团体程序设计天梯赛 L2-009. 抢红包
- 日历管理系统
- CentOS进入单用户模式更改密码
- C语言 程序 取随机数再排序去重
- IO流-序列化流
- 二进制安装mysql5.6乱码终极解决
- Office 文件操作权威指南01
- GBDT