Easy Tutorial
❮ Java Hashmap Containsvalue Java Environment Setup ❯

Java Example - Sum of Numbers

Java Examples

The following example demonstrates the use of the do...while structure to sum the integers from 0 to 100:

Main.java File

public class Main {
    public static void main(String[] args) {
        int limit = 100;
        int sum = 0;
        int i = 1;
        do {
            sum = sum + i;
            i++;
        } while (i <= limit);
        System.out.println("sum=" + sum);
    }
}

The output of the above code is:

sum=5050

Java Examples

❮ Java Hashmap Containsvalue Java Environment Setup ❯