标签:scan ann 死循环 return imp class user public ack
递归就是方法自己调用自己
eg:
用递归实现阶乘
package method;
import java.util.Scanner;
public class Recoursion {
public static void main(String[] args) {
System.out.println("请输入整数,以计算factorial:");
Scanner userInput = new Scanner(System.in);
int intValue = 1;
if (userInput.hasNextInt()) {
intValue = userInput.nextInt();
}
System.out.println(factorial(intValue));
userInput.close();
}
public static int factorial (int n){
if(n==1){
return 1;
}
else return n*factorial(n-1);
}
}
标签:scan ann 死循环 return imp class user public ack
原文地址:https://www.cnblogs.com/ylq167/p/14398737.html