使用while循环语句:

public class Main {
    public static void main(String[] args) {
        int num = 1;
        
        while(num <= 100) {
            if(num % 3 == 0 && num % 7 == 0) {
                System.out.println(num);
            }
            
            num++;
        }
    }
}

使用do-while循环语句:

public class Main {
    public static void main(String[] args) {
        int num = 1;
        
        do {
            if(num % 3 == 0 && num % 7 == 0) {
                System.out.println(num);
            }
            
            num++;
        } while(num <= 100);
    }
}
编写程序输出1到100之间所有可以被3整除又可以被7整除的数。 分别使用while和do_while循环语句改写本程序用java语言

原文地址: https://www.cveoy.top/t/topic/jfHs 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录