JAVA今日2021.8.8

时间:2021-08-08
本文章向大家介绍JAVA今日2021.8.8,主要包括JAVA今日2021.8.8使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

JAVA For

For格式

for(初始化;布尔表达式;更新){
    //代码语句
}

01

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循环结束");
        }
    }

02

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);
    }
}

03

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