Check out example codes for "sum of numbers in java". It will help you in understanding the concepts better.

Code Example 1

public class SumNatural {

    public static void main(String[] args) {

        int num = 100, sum = 0;

        for(int i = 1; i <= num; ++i)
        {
            // sum = sum + i;
            sum += i;
        }

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

Learn ReactJs, React Native from akashmittal.com