class="java" name="code"> package jc; import java.util.Scanner; /** * * 计算前几项的阶乘 * 递归思想 */ public class Jc { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("input the number :"); int n=sc.nextInt(); Jc jc=new Jc(); System.out.print("the result is: "); System.out.println(jc.caculate(n)); } public int caculate(int n){ if(n==1){ return 1; } else{ return n*caculate(n-1); } } }