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

Java Example - Numeric Summing Operation

黄舟
Release: 2017-01-22 15:19:17
Original
1390 people have browsed it

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);
    }}
Copy after login

The output result of the above code is:

sum=5050
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template