赞
踩
- package com.cnstrong.zyf;
- /*
- * 2.编写一个算法求n!。(例如5!= 5*4*3*2*1)
- */
- public class Test2 {
- public int digui(int a){
- if(a==0){
- return 1;
- }else{
- return a * digui(a-1);
- }
- }
-
-
- public int jieCheng(int n) {
- int a = 1;
- if (n == 0) {
- return 1;
- } else {
-
-
- for (int i = a; i <= n; i++) {
- a *= i;
- }
- return a;
- }
- }
- public static void main(String[] args) {
- Test2 t=new Test2();
- System.out.println("结果为:"+t.jieCheng(5));
- System.out.println("采用递归"+t.digui(0));
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。