返回列表 發帖
  1. import java.util.*;
  2. public class Ch01 {

  3.         public static void main(String[] args) {               
  4.                 int n;
  5.                 try
  6.                 {
  7.                         Scanner sc=new Scanner(System.in);
  8.                         n=sc.nextInt();
  9.                 if(n<1 || n>20)
  10.                 {
  11.                         System.out.println("error");
  12.                         return;
  13.                 }
  14.                         System.out.println(compute(n));
  15.                 }catch(Exception e)
  16.                 {
  17.                         System.out.println("error");
  18.                         return;
  19.                 }

  20.         }
  21.         public static long compute(int i)
  22.         {
  23.                 if(i==0)
  24.                         return 1;
  25.                 else
  26.                         return compute(i-1)*i;
  27.         }
  28. }
複製代碼

TOP

返回列表