Ideas:
1. First declare a variable to save the accumulated sum, such as [int sum=0];
2. Then Just use a for loop statement to perform cumulative calculations, such as [for(int x=0;x<=10;x){sum =x}].
(Recommended video tutorial: java video)
Code implementation:
public class for实现 { public static void main(String[] args) { //用for循环实现1-10的和; int sum=0; for(int x=0;x<=10;x++) { sum+=x; } System.out.println("使用for循环得到的sum是:"+sum); } }
Recommended tutorial: java entry program
The above is the detailed content of How to use the for loop statement in java to calculate the cumulative sum of 1~100. For more information, please follow other related articles on the PHP Chinese website!