java寻找奇数除数
我正在试图解决一个关于this page的问题。我想我已经解决了,因为它给了我正确的结果,但当我在网页上提交代码时,它说的是错误的答案。我不明白我的错误在哪里。你能帮帮我吗
class Exercise
{
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int divisor;
int count = 0;
int numbers = 0;
int low;
int high;
// Get the input of the user
public void getInput() throws IOException
{
System.out.println("Please enter k, low and high");
String line1 = input.readLine();
String line2 = input.readLine();
String line3 = input.readLine();
divisor = Integer.parseInt(line1);
low = Integer.parseInt(line2);
high = Integer.parseInt(line3);
}
// Finding number of odd divisors for each number
public void calculate()
{
if ((divisor % 2 != 0)) {
for (int k = low; k <= high; k++) {
count = 0;
for (int j = 1; j <= k; j++) {
if (k % j == 0) {
count++;
}
}
if (count == divisor) {
numbers++;
}
}
System.out.println(numbers);
}
else
System.out.println("Sorry. The divisor should be an odd number. Please try again.");
}
public static void main(String[] args)
{
Exercise obj = new Exercise();
try {
obj.getInput();
obj.calculate();
}
catch(Exception e) {
return;
}
}
}
# 1 楼答案
好的,我做到了。现在它完全按照描述工作。它仍然说-错误的答案
}
# 2 楼答案
根据说明:
您的程序不采用此输入格式。您的程序需要一个单独的测试用例,在3行上分别显示K、low和high。它应该采取多个测试用例,每个测试用例在一行上都有K、low和high