题目:

  编写一个程序,输入n,求n!(用递归的方式实现)。

public class test {

	public static long fac(int n){
		if(n<0){
			return 0;
		}else if(n==0||n==1){
			return 1;
		}else{
			return n*fac(n-1);
		}
	}

	public static void main(String [] args){

		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		System.out.println(fac(n));

	}
} 

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2021-08-28
  • 2021-11-25
  • 2021-04-15
  • 2021-12-07
相关资源
相似解决方案