[英]Write the condition - only one of three numbers are multiple of 5
There should be <=3 comparison operators and no extra parentheses. 应该有<= 3个比较运算符,并且没有多余的括号。 So 所以
condition = x % 5 == 0 ^ y % 5 == 0 ^ z % 5 == 0;
Doesn't test right when X, Y and Z are both multiple of fives 当X,Y和Z均为5的倍数时,测试不正确
Then I expect you want something like 那我希望你想要类似的东西
condition = x % 5 == 0 ? y % 5 != 0 && z % 5 != 0 : y % 5 == 0 ^ z % 5 == 0;
Or 要么
condition = (x % 5 == 0 ? 1 : 0 + y % 5 != 0 ? 1 : 0 + z % 5 != 0 ? 1 : 0) == 1;
Here is a condition: 这是一个条件:
x*y*z % 5 == 0 && (x*y + x*z + y*z + x*y*z % 5 != 0)
The first part means that any of x
, y
or z
is a multiple of 5
(recall that 5
is a prime number!) The second part makes sure that no two of them are. 第一部分表示x
, y
或z
中的任何一个都是5
的倍数(请记住5
是质数!),第二部分确保其中两个都不是。
(I'm not a Java programmer, so please review my syntax!) (我不是Java程序员,所以请检查我的语法!)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.