day03-循环流程-for循环
This commit is contained in:
47
day03/src/com/inmind/for03/Demo05.java
Normal file
47
day03/src/com/inmind/for03/Demo05.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package com.inmind.for03;
|
||||
/*
|
||||
for , while ,do-while 循环
|
||||
循环三要素:循环变量初始化、循环条件、修改循环变量
|
||||
|
||||
for循环的格式:
|
||||
for(循环变量初始化①;循环条件②;修改循环变量④){
|
||||
循环语句③
|
||||
}
|
||||
|
||||
执行顺序:①②③④>②③④>②③④…②不满足为止。
|
||||
|
||||
*/
|
||||
public class Demo05 {
|
||||
public static void main(String[] args) {
|
||||
//打印1~10的值
|
||||
for(int i = 1;i<=10;i++){
|
||||
System.out.println(i);
|
||||
}
|
||||
System.out.println("程序结束");
|
||||
System.out.println("-----------------------");
|
||||
//打印10~1的值
|
||||
for(int j = 10;j>=1;j--){
|
||||
System.out.println(j);
|
||||
}
|
||||
|
||||
System.out.println("-----------------------");
|
||||
//打印a~z的值字符 a = 97 z = 122
|
||||
for(int i = 97; i <=122;i++){
|
||||
System.out.println((char) i);
|
||||
}
|
||||
System.out.println("-----------------------");
|
||||
for (char i = 'a'; i <= 'z'; i++) {
|
||||
System.out.println(i);
|
||||
}
|
||||
System.out.println("-----------------------");
|
||||
for (char i = 'z'; i >= 'a'; i--) {
|
||||
System.out.println(i);
|
||||
}
|
||||
System.out.println("-----------------------");
|
||||
|
||||
//打印100次"hello world"
|
||||
for (int i = 1; i <= 100; i++) {
|
||||
System.out.println("helloworld");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user