
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
Following is the Java program to find the sum of the series −
1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
Example
import java.io.*; import java.lang.*; public class Demo{ public static double pattern_sum(double val){ double residual = 0, factorial_val = 1; for (int i = 1; i <= val; i++){ factorial_val = factorial_val * i; residual = residual + (i / factorial_val); } return (residual); } public static void main(String[] args){ double val = 6; System.out.println("The sum of the series is : " + pattern_sum(val)); } }
Output
The sum of the series is : 2.7166666666666663
A class named Demo contains a function named ‘pattern_sum’. This function takes a double valued number as parameter, and iterates through the value and calculates the series value of (1/1! + 2/2! + ..) and so on. In the main function, the value is defined and the function ‘pattern_sum’ is called by passing this value. The output is displayed on the console.
- Related Articles
- LocalDateTime plus() method in Java
- Duration plus() method in Java
- LocalTime plus() method in Java
- Instant plus() method in Java
- LocalDate plus() method in Java
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Plus One in Python
- Cplus plus vs Java vs Python?
- C Program to check Plus Perfect Number
- C++ program to find the sum of the series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + … + (n*n)
- Sum of the series 1 + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n) in C++
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n! in C++
- Examine whether root 2 plus 2 square is rational or irrational

Advertisements