注意递归函数的返回值要改成long不然在13以后会溢出
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int n=sc.nextInt(); System.out.println(jieChen(n)); } } public static long jieChen(int n){ return n>1?n*jieChen(n-1):1; } }