本帖最後由 吳侑諶 於 2023-10-19 19:29 編輯
- import java.util.Scanner;
- public class JPD02{
- public static void main(String args[]) {
- int n;
- try {
- Scanner sc = new Scanner(System.in);
- n=sc.nextInt();
- if(n<1 || n>20)
- {
- System.out.print("error");
- return;
- }
- System.out.println(compute(n));
- } catch (Exception e) {
- System.out.print("error");
- return;
- }
- }
- public static long compute(int i) {
- if(i==1)
- return 1;
- else
- return compute(i-1)*i;
- }
- }
複製代碼 |