while循环计算1到100的和
时间: 2023-11-01 07:53:03 浏览: 206
使用while循环计算1到100的和的代码如下所示:
```java
public static void main(String\[\] args) {
int i = 1;
int sum = 0;
while(i<=100){
sum = i+sum;
i++;
}
System.out.println(sum);
}
```
\[1\]
#### 引用[.reference_title]
- *1* *2* [Java流程控制:用for循环或while循环计算1~100的和](https://blog.csdn.net/pxqwyy1024/article/details/126226793)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [采用一个while循环,把1到100之间的数值累加起来。](https://blog.csdn.net/weixin_51628454/article/details/109591347)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文