您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

实现5的阶乘,5的阶乘的和

来源:互联网 浏览:46次 时间:2023-04-08

求5的阶乘

创建一个方法求阶乘数值5可以更改为其他数值,如10或者100等。

public class one { public static void main(String[] args) { int retvalue = jiecheng(5) ; //接受返回值 System.out.println(retvalue) ; //输出结果 } //创建阶乘循环方法 public static int jiecheng(int n){ int result = 1; for(int i = n; i>1; i--){ result*=i;//累乘 } return result;//返回阶乘结果 }}``` 99413821