Thursday, 7 January 2021

Jshell: Combine multiple statements

Using ; you can combine multiple statements in single line.

 

Example

System.out.println("Line 1"); System.out.println("Line 2")

 

Step 1: Open terminal and execute the command jshell to open jshell application.

$jshell
|  Welcome to JShell -- Version 10.0.2
|  For an introduction type: /help intro

jshell> 

 

Step 2: Type below command and hit Enter.

System.out.println("Line 1"); System.out.println("Line 2")

jshell> System.out.println("Line 1"); System.out.println("Line 2")
Line 1
Line 2

As you observe the statements, I am not added ; to the last statement.


You no need to put ; to execute single statement.

 

 

jshell> System.out.println("Hello World")
Hello World



 

Previous                                                    Next                                                    Home

No comments:

Post a Comment