Java Examples - Sum of Numbers
The following example demonstrates using the do...while structure to find the sum of integer numbers 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 from running the above code is:
sum=5050Other extensions
Java Examples