Home  >  Article  >  Java  >  While loop 1 adds to the sum of 100

While loop 1 adds to the sum of 100

(*-*)浩
(*-*)浩Original
2019-08-21 11:52:1429827browse

The sum between 1-100, if we use ordinary addition operations, it will be very difficult. This is a waste of time, inefficient, and prone to errors. Here I use a while loop to show you, For beginners to exercise their ideas, it is still very useful to master basic programming.

While loop 1 adds to the sum of 100

First of all, we need to create a class in MyEclipse to perform calculations. When choosing a name, we must pay attention to it and be aware of the name, so that it will be easy for others. Understand what you are trying to do. (Recommended learning: Java Video Tutorial)

While loop 1 adds to the sum of 100After it is established, we will start operating the code. If we want to perform calculations at this time, we have to define the variables we need, so that it is convenient for us to perform calculations

While loop 1 adds to the sum of 100After defining the variables, we will start the loop. When i< ;=100, repeat the addition operation, assign the value of sum i to sum, and increment the value of i after each addition.

While loop 1 adds to the sum of 100

When we loop, we must pay special attention not to forget i; if we do not write this, it will not close, in which case we will output.

While loop 1 adds to the sum of 100While loop 1 adds to the sum of 100

For more Java-related technical articles, please visit the Java Development Tutorial column to learn!

The above is the detailed content of While loop 1 adds to the sum of 100. For more information, please follow other related articles on the PHP Chinese website!

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