首页 > Java > java教程 > 如何在Java 9的JShell中实现关系和逻辑运算符?

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

王林
发布: 2023-08-20 20:41:10
转载
1356 人浏览过

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

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.

Snippet-1

<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>
登录后复制

Snippet-2

<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中文网其他相关文章!

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板