Last Updated: 17 August, 2022
On this tutorial page we are going to learn how to write a Java program to calculate the sum of N natural numbers.
Natural numbers are the positive integers from 1 to infinity, i.e., 1, 2, 3, 4, 5, 6, 7,... Natural numbers do not contain negative numbers or zero.
Natural numbers: 1,2,3,4,5, ....... n
In comparison to whole numbers, natural numbers include all the whole numbers excluding the number 0.
We can find sum of natural numbers in two ways, using mathematical formula or Java loops.
Sum of n natural numbers = n * (n + 1) / 2
Let's see the Java Programs given below.
Output
Sum of Natural Numbers 10 is: 55
Output
Sum of 1 to 50 natural numbers: 1275
Output
Number beginning from: 5
Number ended: 15
Sum: 110
That's all guys, hope this Java Program is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com