【发布时间】:2021-02-20 15:04:14
【问题描述】:
任务是关于所谓的好数字。
如果一个数字% 的每个数字== 0,则该数字是好的。
任务是计算给定范围内的所有好数字。范围是 A 到 B。
例如:13 不是一个好数字,因为13 % 3 != 0。
如果数字为零,我们也必须跳过。
另一个例子102 是一个很好的数字,因为102 % 1 == 0 和102 % 2 == 0。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int[] arrInt = new int[input.length];
arrInt[0] = Integer.parseInt(input[0]);
arrInt[1] = Integer.parseInt(input[1]);
int counter = 0;
boolean isGoodNumber = false;
String s = "";
for (int i = arrInt[0]; i <= arrInt[1]; i++) {
s = Integer.toString(i);
for (int j = 0; j < s.length(); j++) {
if (s.charAt(j) == 0) {
continue;
}
int result = i / s.charAt(j);
if (result % 1 != 0) {
isGoodNumber = false;
break;
}
}
if (isGoodNumber) {
counter += 1;
}
isGoodNumber = true;
}
System.out.println(counter);
}
}
【问题讨论】: