Java Program to find the sum of first 10 natural numbers using class


In this program, You will learn how to find the sum of first 10 natural numbers using class in Java.


Some natural numbers is: 1 2 3 4 5 6 7 8 9 10


Example: How to find the sum of first 10 natural numbers using class in Java

Run it Now
class Main {

    int i, s = 0;

    void print() {
        for (i = 1; i <= 10; i++) {
            s = s + i;
        }

        System.out.println("Sum of 10 natural numbers is :" + s);

    }

    public static void main(String args[]) {

        Main obj = new Main();
        obj.print();
    }
}

Output:

Sum of 10 natural numbers is :55