题解 | #挑7#
挑7
http://www.nowcoder.com/practice/ba241b85371c409ea01ac0aa1a8d957b
解题思路:
1、能够被7整除,则一定是7的倍数
2、不能被7整除,判断是否包含数字7
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int count = 0;
for (int i = 7; i <= n; i++) {
if (isContains(i)) {
count++;
}
}
System.out.println(count);
}
public static boolean isContains(int num) {
String val = String.valueOf(num);
return val.indexOf("7") != -1 || num % 7 == 0;
}
}