mem*_*und 1 java compare biginteger
如果我使用compareToa BigInteger,我如何从结果中选择要调用哪个函数?(-1 = funcA,+ 1 = funcB,0 =无功能).
特别是:这有什么问题?
doCompare() {
BigInteger x = new BigInteger(5);
BigInteger y = new BigInteger(10);
//syntax error token "<", invalid assignment operator
x.compareTo(y) < 0 ? funcA() : funcB();
}
void funcA();
void funcB();
Run Code Online (Sandbox Code Playgroud)
由于funcA()并且funcB()有返回类型void,因此不能使用三元语法.您可以将其重写为常规if语句,但是:
if (x.compareTo(y) < 0) {
funcA();
} else {
funcB();
}
Run Code Online (Sandbox Code Playgroud)