HomePOSTSum of Series Program in Java Language

# Sum of Series Program in Java Language

Sum of Series Program in Java language – Number Series Program in Java | There are lots of series programs are there, we will write a Java program for some of them. After observing these codes you can easily write the program for another sum of series. In another post, we have also written the Fibonacci series program in Java, and Fibonacci Series using Recursion in Java.

• 1+2+3+4+5+..+n
• 12 + 22 + 32 + 42 + 52 +….+ n2
• 1 + 1/2 + 1/3 + 1/4 + 1/5 + 1/6 +……+ 1/n
• 1 + 1/(22) + 1/(33) + 1/(44) + ….. + 1/(nn)
• 1/1! + 2/2! + 3/3! + …… + n/n!
1. Java Sum of Series program for 1+2+3+4+5+..+N

The series 1+2+3+4+5+..+N is the sum of first N natural numbers. To find the sum of this series we have to take the help of loop.

## Sum of Series Program in Java – series:- 1 + 2 + 3 + 4 + … + N

``````
import java.util.Scanner;
public class Series {
public static void main(String[] args) {

// create Scanner class object
Scanner scan = new Scanner(System.in);

// declare variables
int n;
int sum = 0;

System.out.print("Enter N value: ");
n = scan.nextInt();

// calculate the sum of series
for(int i=1; i<=n; i++) {
sum = sum + i;
}

// display result
System.out.println("Sum = " + sum);
}
}

``````

## OUTPUT

``````

Enter N value: 5
Sum = 15

``````

## Types of Sorting Algorithms:

If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.

Thank you 😊 Keep Learning !

RELATED ARTICLES