for(初始化;布尔表达式;更新){
//代码语句
}
package JAVASE.struct;
public class For01 {
public static void main(String[] args) {
// 初始化;条件判断;更新
for (int i =1;i<=100;i++){
System.out.println(i);
}
System.out.println("for循环结束");
}
}
package JAVASE.struct;
public class For02 {
public static void main(String[] args) {
//计算0到100之间的奇数和偶数的和
int os = 0;
int es = 0;
for (int i = 0; i <= 100; i++) {
if (i%2!=0){
os+=i;
}else {
es+=i;
}
}
System.out.println("os:"+os);
System.out.println("es:"+es);
}
}
package JAVASE.struct;
public class For03 {
public static void main(String[] args) {
//输出1-1000之间能被5整除的数,每行三个
for (int i = 0; i <= 1000; i++) {
if (i%5==0){
System.out.print(i+"\t");
}
if (i%(5*3)==0){
System.out.println();
}
}
}
}
2021.8.8
原文:https://www.cnblogs.com/Walf1234/p/15116485.html