forked from DuGuQiuBai/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForTest6.java
More file actions
35 lines (31 loc) · 613 Bytes
/
ForTest6.java
File metadata and controls
35 lines (31 loc) · 613 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
需求:请统计1-1000之间同时满足如下条件的数据有多少个:
对3整除余2
对5整除余3
对7整除余2
分析:
A:定义一个统计变量。
B:1-1000之间告诉我们了范围,用for循环可以解决
C:条件
对3整除余2
对5整除余3
对7整除余2
x%3 == 2
x%5 == 3
x%7 == 2
*/
class ForTest6 {
public static void main(String[] args) {
//定义一个统计变量。
int count = 0;
//1-1000之间告诉我们了范围,用for循环可以解决
for(int x=1; x<=1000; x++) {
//判断条件
if(x%3==2 && x%5==3 && x%7==2) {
//System.out.println(x);
count++;
}
}
System.out.println("共有"+count+"个满足条件的数据");
}
}