Share your repls and programming experiences

← Back to all posts
Write a program to print first ten natural numbers in java
RaghunathThilag (1)

Write a program to print first ten natural numbers in java. In this program you will learn how to write a program to sum of the natural numbers in java for beginners. In Java programming language, the sum of natural numbers. In the Java programming language, this is an example of a simple set program. The sum of natural numbers program is essentially an addition program that is run in a for loop

public class Main
{
public static void main(String[] args)
{
int number = 10, sum = 0;
for(int i = 1; i <= number; ++i)
{
sum =sum + i;
}
System.out.println("Sum = " + sum);
}
}

Output:

Sum = 55

Link: https://inlarn.com/write-a-program-to-print-first-ten-natural-numbers-in-java/