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

 1 public class Demo {
 2 
 3     public static void main(String[] args) {
 4 
 5         /*
 6          * 求出1~100之间,既是3又是7的倍数的自然数出现的次数
 7          */
 8         int count = 0; // 计数
 9         for (int i = 1; i <= 100; i++) {
10             if (i % 3 == 0 && i % 7 == 0) {
11                 System.out.println(i);
12                 count++;
13             }
14         }
15         
16         System.out.println("个数为:" + count); // 21 42 63 84
17     }
18 }

猜你喜欢

转载自www.cnblogs.com/stefaniee/p/10908402.html