0
点赞
收藏
分享

微信扫一扫

java求出1~100之间,既是3又是7的倍数的自然数出现的次数?

_karen 2022-01-22 阅读 84

1)打印1~100之间 6的倍数的个数
2)求出1~100之间,既是3又是7的倍数的自然数出现的次数?

class Exer1{
	public static void main(String[] args) {	
		int count1 = 0, count2 = 0;
		for (int x = 1;x <= 100;x++){
			if(x % 6 ==0){
				count1++;
			}
			if (x % 3 == 0 && x % 7 ==0){
				count2++;
			}
		}
		System.out.println("6的倍数的个数=" + count1);
		System.out.println("既是3又是7的倍数的个数=" + count2);
	}
}
举报

相关推荐

0 条评论