简体   繁体   English

Java 右侧小于等于的语句

[英]Java statement with less than equal to on the right side

Here's a line from a large Java program which compiles without errors.这是一个大型 Java 程序中的一行代码,它编译时没有错误。 I'm unable to understand how the <= operator is being used on the right side of assignment statement:我无法理解如何在赋值语句的右侧使用 <= 运算符:

converged = measure.distance(centroid.getLengthSquared(), centroid, getCenter()) <= convergenceDelta;

Is this some obscure Java feature?这是一些不起眼的 Java 功能吗?

No, it's not.不,这不对。

As you will see converged will be of boolean type.如您所见, converged将是boolean类型。

It will be exactly the same as saying和说的完全一样

boolean foo = 2 <= 3;

So, probably in your code measure.distance(centroid.getLengthSquared(), centroid, getCenter()) returns a number which is then compared using the relational <= operator with convergenceDelta;因此,可能在您的代码measure.distance(centroid.getLengthSquared(), centroid, getCenter())返回一个数字,然后使用关系<=运算符将其与convergenceDelta;进行比较. . The result will be true or false , a boolean value which will be saved at converged .结果将是truefalse ,一个 boolean 值将在converged时保存。

Not at all.一点也不。 <= and the other relational operators return boolean values. <=和其他关系运算符返回 boolean 值。 If converged is a boolean variable, you can assign that value to it.如果converged的是 boolean 变量,则可以将该值分配给它。

It is setting converged to the truth statement of the distance being less than or equal to the value on the variable convergenceDelta.它设置收敛到距离小于或等于变量convergenceDelta 上的值的真值陈述。

<= is a binary operator like any other. <= 和其他运算符一样是二元运算符。 The value of it is true if LHS <= RHS, and false if not.如果 LHS <= RHS,则它的值为 true,否则为 false。

So in this case, if the distance is less than the convergence delta it's considered to have converged.所以在这种情况下,如果距离小于收敛增量,则认为它已经收敛。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java中“小于或等于”的运算符是什么? - What is the operator for “Less than or Equal to” in Java? 如何在if / else语句中检查整数且小于或等于100 - How to check for integer and less than or equal to 100 in an if/else statement 小于或等于GregorianCalendar - Less than or equal to with GregorianCalendar 如何在Java中的单个if语句中使用大于和小于 - how to use greater than and less than in a single if statement in java 客户端Java本质上不如JavaScript安全吗? - Is client-side java intrinsically less secure than javascript? 如果 arraylist 的总和小于或等于最大数,如何返回 boolean 语句? - How to return boolean statement if the sum of an arraylist is less than or equal to a maximum number? 打印小于或等于56且数字总和大于10的两位数 JAVA - print two digit numbers which are less than or equal to 56 and the sum of digits is greater than 10 JAVA 如果EditText字段小于或等于13.5且大于33.0,则隐藏按钮-Java Android - Hide a Button if EditText field is less than or equal to 13.5 & greater than 33.0 - Java Android JAVA中计算所有小于或等于N数的乘法表的程序 - Program that compute the multiplication table for all numbers less than or equal N in JAVA 在Java中,就性能而言,&lt;=比较是否等于小于比较,然后是OR,然后是等于比较? - In Java, in terms of performance, is a <= comparison the same as a less than comparison followed by an OR followed by an equal to comparison?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM