
JShell has introduced in Java 9 that enables us to explore, discover, and experiment with Java language features, and extensive libraries.
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.
<strong>jshell> int i = 10; i ==> 10 jshell> i > 10; $2 ==> false jshell> i >= 10; $3 ==> true jshell> i < 10; $4 ==> false jshell> i <= 10; $5 ==> true jshell> i == 10; $6 ==> true jshell> i == 20; $7 ==> false</strong>
<strong>jshell> int i = 15; i ==> 15 jshell> i >=15 $1 ==> true jshell> i <= 15 $2 ==> true jshell> i >= 15 && i <= 25 $3 ==> true jshell> i == 30; $4 ==> false jshell> i = 30; i ==> 30 jshell> i >= 15 && i <= 25; $5 ==> false</strong>
在下面的代码片段中,我们可以使用JShell实现逻辑运算符。
<strong>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</strong>
以上就是如何在Java 9的JShell中实现关系和逻辑运算符?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号