Home  >  Article  >  Java  >  Java Example - Numeric Summing Operation

Java Example - Numeric Summing Operation

黄舟
黄舟Original
2017-01-22 15:19:171362browse

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

/*
 author by w3cschool.cc
 Main.java
 */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 result of the above code is:

sum=5050

The above is the Java example - digital sum operation. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn