java给定两个数字,如果其中任何一个除以另一个,则返回true,否则返回false
给定两个数字,如果其中任何一个除以另一个,则返回true,否则返回false
public class DividesAB {
static int testcase11 = 208;
static int testcase12 = 7;
boolean aDivisblebyb, bDivisblebya, answer;
public static void main(String args[]){
DividesAB testInstance = new DividesAB();
boolean result = testInstance.divides(testcase11,testcase12);
System.out.println(result);
}
//write your code here
public boolean divides(int a, int b){
boolean aDivisiblebyb = a%b == 0;
boolean bdivisiblebya = b%a == 0;
boolean answer = aDivisiblebyb||bDivisiblebya;
return answer;
}
}
我一直收到类似cannot find symbol
的错误
# 1 楼答案
你有一堆乱七八糟的代码,其中一半是不需要的。要查找符号是否未定义,请查看IDE中它抱怨的代码行,并查看该变量不在范围内的原因
如果你只写你需要的代码,那么犯错误的机会就少了,而且更容易看出错误在哪里
我就是这样写的
# 2 楼答案
变量名不正确
因此,更改变量名应该会起作用