用intellij idea求n的阶乘 PTA题库

根据输入的整数n,输出n的阶乘
输入格式:
n
输出格式:

n!
输入样例:
3
结尾无空行
输出样例:
6
结尾无空行


public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int n = x;
        int res = 1;
        while ( n > 0){
            res *= n;
            n--;
        }
        System.out.println(res);
    }