做法是按位取余,这里换个写法。
转换为StringBuilder:
public class Main {
public static void main(String[] args) {
int sum = 0;
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for (int i = 1; i <= n; i++) {
StringBuilder si = new StringBuilder(String.valueOf(i));
if(si.indexOf("1") != -1 | si.indexOf("0") != -1 | si.indexOf("2") != -1 | si.indexOf("9") != -1){
sum+=i;
}
}
System.out.println(sum);
}
}