当前位置:网站首页>循环结构--do-while循环
循环结构--do-while循环
2022-08-02 10:15:00 【白茶清欢*】
一、do-while循环
1.、循环结构的四个要素
① 初始化条件
② 循环条件 —> 是 boolean 类型
③ 循环体
④ 迭代条件
2.、do-while 循环的结构
①
do{
③ ;
④ ;
}while( ② );
3、执行过程:① - ③ - ④ - ② - ① - ③ - ④ - … - ②
4、说明:do-while 循环至少执行一次循环体。
1)不在循环条件部分限制次数的结构:
while(true) , for(true)
2)结束循环的几种方式:
方式一:循环条件部分返回 false;
方式二:在循环体中,执行 break;
二、do-while循环练习
1.遍历100以内的偶数,并计算所有偶数的和及偶数的个数
class DoWhileTest{
public static void main(String[] args){
int num=1;
int sum=0;//记录总和
int count=0;//记录个数
do{
if(num%2==0){
System.out.println(num);
sum+=num;
count++;
}
num++;
}while(num<=100);
System.out.println("总和为:"+sum);
System.out.println("总和为:"+count);
}
}
边栏推荐
- Linux系统卸载,安装,升级,迁移clickHouse数据库
- 瑞萨RZ/G2L处理器详细测评
- R language ggplot2 visualization: based on the fill parameter and shape parameter in the aes function, custom draw a grouped line chart and add data points (scatter points), use the legend.position fu
- Linux system uninstall, install, upgrade, migrate clickHouse database
- R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
- DirectX修复工具增强版「建议收藏」
- Do you agree with this view?Most businesses are digitizing just to ease anxiety
- STL中list实现
- 3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
- 使用较广泛的安全测试工具有哪些?
猜你喜欢

MySql千万级分页优化,快速插入千万数据方法

iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?

Verilog's random number system task----$random

软件测试与质量 之白盒测试

4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...

How to choose a truly "easy-to-use, high-performance" remote control software

基于列表的排队与叫号系统

太帅了!我用炫酷大屏展示爬虫数据!

软件测试X模型

食品安全 | 鱼肝油不是鱼油,家有宝宝的注意了
随机推荐
周杰伦新歌发布,爬取《Mojito》MV弹幕,看看粉丝们都说的些啥!
games202:三,实时环境光照IBL + PRT
LayaBox - TypeScript - merge statement
转转反爬攻防战
wireshark的安装教程(暖气片安装方法图解)
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!
基于列表的排队与叫号系统
yolov7 innovation point
R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)
练习16-两道模拟题
Verilog's random number system task----$random
LayaBox---TypeScript---Decorator
8月份的.NET Conf 活动 专注于 .NET MAUI
Spearman's correlation coefficient
第十五章 多线程
4年手工测试被应届生取代了,用血与泪的教训给xdm一个忠告,该学自动化了...
适配器模式适配出栈和队列及优先级队列
iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
Hongxing, donate another million
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?