[英]Check two conditions with two different outcomes (ternary operators)
我创建了一个变量,
newval1 = lb + (ub - lb)*rnd.nextDouble();
它必须位于两个值之间, bounds[0]
和bounds[1]
。 目前,我使用三元运算符在两行中实施了此检查:
newval1 = ((newval1<bounds[0]) ? bounds[0] : newval1);
newval1 = ((newval1>bounds[1]) ? bounds[1] : newval1);
毫无疑问,有一种更有效的方法可以将newval1
与这些界限进行比较,最好在1行中。 有什么建议么?
val = Math.min(bounds[1], Math.max(bounds[0], val));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.