day03--循环流程-for循环
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.inmind.for03;
|
||||
/*
|
||||
for , while ,do-while 循环
|
||||
循环三要素:循环变量初始化、循环条件、修改循环变量
|
||||
|
||||
for循环的格式:
|
||||
for(循环变量初始化①;循环条件②;修改循环变量④){
|
||||
循环语句③
|
||||
}
|
||||
|
||||
执行顺序:①②③④>②③④>②③④…②不满足为止。
|
||||
|
||||
*/
|
||||
public class Demo05 {
|
||||
public static void main(String[] args) {
|
||||
//跑个10圈:1~10圈
|
||||
for(int i = 1; i<=10 ;i++){
|
||||
System.out.println("当前跑了第"+i+"圈");
|
||||
}
|
||||
System.out.println("------------------------------");
|
||||
//跑个10圈:倒着数10~1
|
||||
for(int i =10;i>=1;i--){
|
||||
System.out.println("当前跑了第"+i+"圈");
|
||||
}
|
||||
System.out.println("------------");
|
||||
|
||||
//输出26个小写字母 a~z ,字符的强转 a--97~+25,也可以直接用字符
|
||||
for (int i = 97; i <= 122; i++) {
|
||||
System.out.println((char) i);
|
||||
}
|
||||
|
||||
System.out.println("-----------------------");
|
||||
//其实在运算时,char本身会自动提升为int
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
System.out.println("程序结束");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user