返回列表 發帖
本帖最後由 吳侑諶 於 2023-10-19 19:29 編輯
  1. import java.util.Scanner;

  2. public class JPD02{

  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.             {
  10.                 System.out.print("error");
  11.                 return;
  12.             }
  13.             System.out.println(compute(n));
  14.         } catch (Exception e) {
  15.             System.out.print("error");
  16.             return;
  17.         }
  18.     }

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

TOP

返回列表