如何在Java 9的JShell中实现关系和逻辑运算符?

2023年 8月 28日 38.0k 0

如何在Java 9的JShell中实现关系和逻辑运算符?

The relational operators (==, != , =) can be used mainly for comparison. It accepts operands of non-boolean primitive data types and returns a boolean value. JShell also supports logical operators that can be used in expressions. The logical operators can expect boolean operands. The expressions involving these operands can be used for forming boolean conditions in the code within if, for, and while statements. The logical operators include : "&& : logical AND", "|| : OR" and "! : NOT".

In the below two code snippets, we can implement relational operators using JShell.

Snippet-1

jshell> int i = 10;
i ==> 10

jshell> i > 10;
$2 ==> false

jshell> i >= 10;
$3 ==> true

jshell> i false

jshell> i true

jshell> i == 10;
$6 ==> true

jshell> i == 20;
$7 ==> false

登录后复制

Snippet-2

jshell> int i = 15;
i ==> 15

jshell> i >=15
$1 ==> true

jshell> i true

jshell> i >= 15 && i true

jshell> i == 30;
$4 ==> false

jshell> i = 30;
i ==> 30

jshell> i >= 15 && i false

登录后复制

在下面的代码片段中,我们可以使用JShell实现逻辑运算符。

jshell> true && true
$1 ==> true

jshell> true && false
$2 ==> false

jshell> false && true
$3 ==> false

jshell> false && false
$4 ==> false

jshell> true || true
$5 ==> true

jshell> true || false
$6 ==> true

jshell> false || true
$7 ==> true

jshell> false || false
$8 ==> false

登录后复制

以上就是如何在Java 9的JShell中实现关系和逻辑运算符?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论