Java 9引入了JShell,它允许我们评估代码片段,例如声明、语句和表达式。 在下面的代码片段中,我们创建了变量x、y和str。我们可以使用"/list"命令查看所有输入的代码片段。之后,我们可以使用"/reset"命令来重置当前会话。 jshell> int a = 25 a ==> 25 jshell> double y = 30 y ==> 30.0 jshell
回文字符串字符串是一个字符串,当颠倒过来或单词在向前和向后方向拼写相同时,它保持不变。 p> 在下面的示例中,我们可以在 JShell 工具中检查给定的字符串是否是回文。 C:UsersUser>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> S
A switch statement can test multiple conditions just like an else clause and handles the default possibility. The default clause can be executed when none of the cases match, and a break statement can
在下面的示例中,我们可以在JShell中实现一个lambda表达式。 C:UsersUser>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> Consumer s = (String s) -> System.out.println(s) s =
If we want to get the current date with time in JShell by using the below code snippet. C:UsersUser>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> ne