day03-.while循环的语法&练习
This commit is contained in:
43
day03/src/com/inmind/Demo04_while.java
Normal file
43
day03/src/com/inmind/Demo04_while.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.inmind;
|
||||
/*
|
||||
while循环的格式和使用
|
||||
|
||||
循环变量初始化①
|
||||
while(循环条件②){
|
||||
循环体语句③
|
||||
修改循环变量④
|
||||
}
|
||||
|
||||
执行顺序:①②③④>②③④>②③④…②不满足为止
|
||||
*/
|
||||
public class Demo04_while {
|
||||
public static void main(String[] args) {
|
||||
//使用while的语法,计算出1~100的偶数累和
|
||||
}
|
||||
|
||||
|
||||
//while循环的语法学习
|
||||
public static void whileMethod(String[] args) {
|
||||
//打印1~10
|
||||
int i = 1;
|
||||
while(i<=10){
|
||||
System.out.println(i);
|
||||
i++;
|
||||
}
|
||||
System.out.println("------------------");
|
||||
//打印10~1
|
||||
int j = 10;
|
||||
while (j>=1) {
|
||||
System.out.println(j);
|
||||
j--;
|
||||
}
|
||||
System.out.println("------------------");
|
||||
|
||||
//打印A~Z
|
||||
int k = 'A';
|
||||
while (k <= 'Z') {
|
||||
System.out.println((char)k);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user