1 public class Demo { 2 public static void main(String[] args) { 3 Scanner sc = new Scanner(System.in); 4 System.out.println("请输入一个数:"); 5 int i = sc.nextInt(); 6 System.out.println(i+"!为 "+getFac(i)); 7 sc.close(); 8 } 9 10 private static int getFac(int i) { 11 // TODO Auto-generated method stub 12 if (i<=0) { 13 return 0; 14 }else if (i==1) { 15 return 1; 16 }else { 17 return getFac(i-1)*i; 18 } 19 } 20 }
原文:http://www.cnblogs.com/zxinyu/p/7707380.html