当前位置:网站首页>循环结构--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);
}
}
边栏推荐
- 全新荣威RX5,27寸大屏吸引人,安全、舒适一个不落
- R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
- 行为型模式-模板方法模式
- List-based queuing and calling system
- 瑞萨RZ/G2L处理器详细测评
- 练习16-两道模拟题
- Rust 从入门到精通03-helloworld
- Linux system uninstall, install, upgrade, migrate clickHouse database
- 行为型模式-策略模式
- QT专题:事件机制event基础篇
猜你喜欢

MSYS2 QtCreator Clangd code analysis can not find mm_malloc.h problem remedy

Spearman's correlation coefficient

QT专题:自定义部件

QT专题:事件机制event基础篇

周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...

QT专题:组合会话框和文本编辑器

Why use BGP?

享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世

软件工程国考总结——选择题

npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
随机推荐
This article takes you to understand the commonly used models and frameworks of recommender systems
List-based queuing and calling system
Geoffery Hinton:深度学习的下一个大事件
LayaBox---TypeScript---Mixins
【OpenCV】-霍夫变换
软件测试与质量 之白盒测试
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化、使用diff函数计算对数化后的时间序列数据的逐次差分(计算价格的对数差分)
众城优选系统开发功能
练习-17
向量点积(Dot Product),向量叉积(Cross Product)
牛客网项目17节生成验证码 刷新验证码一直没反应
DVWA 通关记录 2 - 命令注入 Command Injection
开源一夏 | GO语言框架中如何快速集成日志模块
SVN如何删除文件名包含空格的文件
yolov7 innovation point
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
LayaBox---TypeScript---高级类型
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
鸿星尔克再捐一个亿
使用较广泛的安全测试工具有哪些?