1 package study; 2 import java.util.*; 3 import java.math.*; 4 5 public class myClass { 6 public static void main(String[] args){ 7 System.out.println("请输入x的值"); 8 Scanner in=new Scanner(System.in); 9 int x=in.nextInt(); 10 long ans = 1; 11 for(int i=1;i<=x;i++){ 12 ans=ans*i; 13 } 14 System.out.println("x的阶乘是"+ans); 15 } 16 }