返回列表 發帖
  1. import java.util.Scanner;

  2. public class JPD03 {
  3.         public static void main(String[] args) {
  4.              int n;
  5.              try{
  6.                      Scanner sc=new Scanner(System.in);
  7.                      n=sc.nextInt();
  8.                      if(n<1 || n>20){
  9.                              System.out.println("error");
  10.                              return;
  11.                      }
  12.                              System.out.println(compute(n));
  13.                      
  14.             }catch(Exception e){
  15.                     System.out.print("error");
  16.                     return;
  17.             }
  18.          }
  19.         public static int compute(int i){
  20.               if(i==1)
  21.                  return 1;
  22.               else
  23.                       return compute(i-1)*i;
  24.            }   
  25.         }
  26.      
  27.    
複製代碼

TOP

返回列表