You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jshell.md
+39-13
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
# Jshell online compiler
2
-
Write, Run & Share Jshell code online using OneCompiler's Jshell online compiler for free. It's one of the robust, feature-rich online compilers for Jshell language, running the Jshell version 11. Getting started with the OneCompiler's Jshell editor is easy and fast. The editor shows sample boilerplate code when you choose language as Jshell and start coding.
2
+
Write, Run & Share Jshell code online using OneCompiler's Jshell online compiler for free. It's one of the robust, feature-rich online compilers for Jshell language, running the Jshell version 17. Getting started with the OneCompiler's Jshell editor is easy and fast. The editor shows sample boilerplate code when you choose language as Jshell and start coding.
3
3
4
4
# About Jshell
5
5
@@ -12,12 +12,22 @@ In short, Jshell creates a simple and easy programming environment in the comman
12
12
13
13
## Variables
14
14
When you evaluate any valid java expression, the result will be stored in the system defined variables.
15
-
16
15
You can also create your own variables
17
16
18
-
### Syntax
19
17
```java
20
-
datatype variable name = value;
18
+
// datatype variable name = value;
19
+
int age =16; // example
20
+
```
21
+
22
+
## Taking inputs (stdin)
23
+
By default Jshell creates a new VM to run the code which makes the System.in unavialble to use. OneCompiler has a workaround to this by adding `--execution local` param. User need to mention this in comments to make use of this option. Following is an example program to demonstrate this
24
+
25
+
```java
26
+
//--execution local
27
+
Scanner input =newScanner(System.in);
28
+
System.out.println("Enter your name: ");
29
+
String inp = input.next();
30
+
System.out.println("Hello, "+ inp);
21
31
```
22
32
23
33
## Control statements
@@ -26,31 +36,47 @@ datatype variable name = value;
26
36
27
37
When ever you want to perform a set of operations based on a condition If-Else is used.
28
38
39
+
Syntax:
40
+
29
41
```java
30
-
if(conditional-expression) {
31
-
// code
42
+
if(condition) {
43
+
// code when condition true
32
44
} else {
33
-
// code
45
+
// code when condition false
34
46
}
35
47
```
36
-
### Example:
48
+
49
+
Example:
50
+
37
51
```java
38
-
intx=3
39
-
if(x%2==0) {
52
+
inti=3
53
+
if( i%2==0) {
40
54
System.out.println("Even number");
41
55
} else {
42
56
System.out.println("Odd number");
43
57
}
44
58
```
59
+
45
60
### 2. For:
46
61
47
62
For loop is used to iterate a set of statements based on a condition. Usually for loop is preferred when number of iterations is known in advance.
0 commit comments