1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
自行实现
public class HJ055 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(getSevenRelCnt(sc.nextInt(), 7));
}
public static int getSevenRelCnt(int n, int target) {
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (i % target == 0 || contain(i, target)) {
cnt++;
}
}
return cnt;
}
public static boolean contain(int x, int target) {
while (x > 0) {
if (x % 10 == target) {
return true;
}
x = x / 10;
}
return false;
}
}