递归求 N 的阶乘
import java.util.Scanner; public class Test28 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("请输入N:"); int num =scanner.nextInt(); int s=func(num); System.out.println(num+"的阶乘为:"+s); } private static int func(int num) { if(num==1){ return 1; }else{ return num*func(num-1); } } }
实现结果:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)