Syntax
dataType variableName
dataType variableName = value
Step 1: Open terminal and execute the command jshell.
$jshell
| Welcome to JShell -- Version 10.0.2
| For an introduction type: /help intro
jshell>
Step 2: Execute below statement.
int x
jshell> int x
x ==> 0
‘x ==> 0’ specifies that x contains value 0.
Step 3: Just type the variable ‘x’ and press enter key to know the value of variable x.
jshell> x
x ==> 0
You can assign any other value to x.
jshell> x = 30
x ==> 30
jshell> x = 40
x ==> 40
Can I declare the variable twice in jshell?
Yes, you can declare. In this case recent declaration overrides previous declaration.
jshell> int a = 10
a ==> 10
jshell> int a = 20
a ==> 20
jshell> a
a ==> 20
No comments:
Post a Comment