MeshWorld India LogoMeshWorld.
ProgramJAVA2 min read

A Program to display sum of 1 to 10 numbers using for loop in JAVA

(Updated: Jun 22, 2026)
Listen to ArticleAI Speech
~2 min read narration
100%
A Program to display sum of 1 to 10 numbers using for loop in JAVA

A program to find sum of 1 to 10 an integer numbers using for loop in JAVA

Algorithm for sum of 1 to n

Step 1: Start
Step 2: Read a number n
Step 3: Initialize variables: i = 1, result = 0
Step 4: if i <= n go to Step 4 otherwise go to Step 7
Step 5: Calculate result = result + i
Step 6: Increment the i by 1 (i = i + 1) and go to Step 3
Step 7: Display result
Step 8: Stop


As 0 is an identity for addition i.e whenever any number is added to 0, same value is obtained. For e.g 7 + 0 = 7 Thats why we assign result = 0 as initial value

Working example

/**
 * Sum of 1 to 10 using for loop
 */
class SumDemoUsingForLoop
{
    public static void main(String[] args)
    {
        int i, result = 0, n = 10;

        for (i = 1; i <= n; i++)
        {
            // System.out.println("I: " + i);
            // System.out.println("Result B4: " + result);
            result += i;
            // System.out.println("Result After: "+ result);
        }

        System.out.println("Sum of series:" + result);
    }
}

Output

Sum of series: 55
Reader Quality Feedback

Did this technical guide help solve your problem?

Suggest Errata ($0)
Vishnu
Primary Author

Vishnu

Founder & Principal Architect at MeshWorld. Senior engineer and instructor specializing in AI agent systems, scalable web architecture, and modern development workflows.

Explore Author Archive
Compute Fuel & Open Testbed
100% Independent & Verified

Fuel High-Density, Zero-Fluff Engineering Deep-Dives

Every guide on MeshWorld is validated on physical Linux nodes and reproducible testbeds. If this article saved you hours of debugging or unblocked production, consider funding our next cluster run.

Weekly Dispatch

Join MeshWorld Dispatch

Get practical tutorials, system blueprints, and curated AI engineering notes straight to your inbox. No fluff, zero spam.

Zero spam. 1-click unsubscribe anytime.Prefer RSS?
Curated Continuations

Up Next in This Domain.

Browse Full Archive