用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个

菜鸟日记 / 2024-02-06 / 原文

需求

用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个

代码实现

package com.jichu.struct;

public class ForDemo02 {
    public static void main(String[] args) {
        //用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个的需求
        for (int i = 1; i <= 100; i++){
            if(i%5==0){
                System.out.print(i+"\t");
            }
            if(i%15==0){
                System.out.print("\n");
            }
        }
    }
}

思路

利用print和println的区别

运行结果