循环
来源:互联网 发布:相似度算法 编辑:程序博客网 时间:2024/05/16 10:14
1 while循环
public class Test{
public static void main(String[] args){
int count = 0; //初始化条件
while(count<10){ //循环条件
System.out.println("count = "+count); //循环体
count++; //迭代语句
}
System.out.println("循环结束");
}
}
2 do while 循环
public class Test{
public static void main(String[] args){
int count = 0;
do{
count++;
System.out.println("count = "+count);
}while(count<10);
System.out.println("循环结束");
}
}
3 for循环
public class TestDmo{
public static void main(String[] args){
int count = 0;
for(int i=0 ;i<10; i++){ //执行过程:最开始 i=0,count=0; 当i=0,判断i小于10吗?
//当i<10为true时,执行循环体,接着执行i++(迭代语句)
System.out.println("i="+i); //当i=9,输出i=9,count++后,count为10,再执行i++,i为10 ,
count++; //再次判断10<10?结果为false,则不再执行循环体。
System.out.println("count="+count);
}
System.out.println("循环结束");
}
}
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- 最短路 多条路径
- c++随机数 普通和高斯分布
- 通过绑定修改DataGrid的Column的Visibility
- MySQL修改root密码的4种方法
- 动态网页开发基础
- 循环
- Linker command failed with exit code 1(use -v to see invocation)
- CCF NOI1044 最近元素
- 打印uboot和内核系统的启动信息方法
- 分布式调用跟踪与监控实战
- jsp基础
- PHP基础知识总结--第二弹
- 挂载ASM磁盘组
- C++ 上机实验(三)【模板】