---
title: "求和函数 1+  1/2!  +1/3!  + .... + 1/n!"
author: "卑微的去爱你"
date: "2015-02-06T16:16:00Z"
tags: []
slug: "1-1-2-1-3-1-n"
draft: false
lastmod: "2015-06-19T16:43:20Z"
id: 2220917
url: "https://linuxdev.iteye.com/blog/2220917"
---

```
/*
 *  求和函数 1+  1/2!  +1/3!  + .... + 1/n!
 * 
 * 
 * */

package com.mingrsoft;

public class Examlpe {
	public static void main(String[] args) {
		//jieCheng(4);
		
		//sum(3);
		
	}
	
	//求阶乘函数  n!
	public static double jieCheng(double shuzhi)
	{
		double zongshu=1,i=1;
	
		while(i<=shuzhi)
		{
			zongshu=zongshu*i;
			i++;
		}
		
		//System.out.println(1/zongshu);
		return 1/zongshu;  // 求出 1/n！
	}
	
	
	// 求出总和，调用 1/n！  函数
	public static double sum(double shu)
	{
		double all=0,n=1;
		
		while(n<=shu)
		{
			all=all+jieCheng(n);
			n++;
			
		}
		System.out.println(all);
		return all;
	}  

}
```

各个击破，模块设计