递归:打印1-10 递归方法理解

递归的本质就是自己调用自己的方法
递归头:结束该递归
**递归体:**递归实现的方法(重复调用)

代码:

package 第8章io;
/**
 * 递归:方法自己调用自己
 * 递归头:何时结束递归
 * 递归体:重复调用
 * @author thinkpad
 *
 */

public class DirDemo03 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		printTen(1);
	}
	//打印1-10;
	public static void printTen(int n) {
		if(n>10) {//递归头结束递归
			return ;
		}
		System.out.println(n);
		printTen(n+1);//递归体
		//方法自己 调用自己
	}

}

在这里插入图片描述
喜欢我的可以关注我,我们可以一起交流学习

微信公众号:

让我爱上它Computer

qq群:473989408

发布了68 篇原创文章 · 获赞 15 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_42913025/article/details/102456539