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 }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-08-17
  • 2021-09-06
  • 2022-12-23
  • 2022-01-19
  • 2021-05-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-09-12
  • 2022-12-23
  • 2021-04-14
相关资源
相似解决方案