Skip to content

Commit ce02d13

Browse files
jshell stdin fixes
1 parent 74ffca4 commit ce02d13

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

jshell.md

+39-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# 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.
33

44
# About Jshell
55

@@ -12,12 +12,22 @@ In short, Jshell creates a simple and easy programming environment in the comman
1212

1313
## Variables
1414
When you evaluate any valid java expression, the result will be stored in the system defined variables.
15-
1615
You can also create your own variables
1716

18-
### Syntax
1917
```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 = new Scanner(System.in);
28+
System.out.println("Enter your name: ");
29+
String inp = input.next();
30+
System.out.println("Hello, " + inp);
2131
```
2232

2333
## Control statements
@@ -26,31 +36,47 @@ datatype variable name = value;
2636

2737
When ever you want to perform a set of operations based on a condition If-Else is used.
2838

39+
Syntax:
40+
2941
```java
30-
if(conditional-expression) {
31-
// code
42+
if(condition) {
43+
// code when condition true
3244
} else {
33-
// code
45+
// code when condition false
3446
}
3547
```
36-
### Example:
48+
49+
Example:
50+
3751
```java
38-
int x = 3
39-
if(x%2 == 0) {
52+
int i = 3
53+
if( i%2 == 0 ) {
4054
System.out.println("Even number");
4155
} else {
4256
System.out.println("Odd number");
4357
}
4458
```
59+
4560
### 2. For:
4661

4762
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.
4863

64+
Syntax:
65+
4966
```java
50-
for(Initialization; Condition; Increment/decrement){
51-
//code
67+
for( Initialization; Condition; Increment/decrement ){
68+
//code
5269
}
5370
```
71+
72+
Example:
73+
74+
```java
75+
for(int i = 1; i <= 10; i++ ){
76+
Systen.out.println(i);
77+
}
78+
```
79+
5480
### 3. While:
5581

5682
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
@@ -67,4 +93,4 @@ Do-while is also used to iterate a set of statements based on a condition. It is
6793
do {
6894
// code
6995
} while (condition);
70-
```
96+
```

0 commit comments

Comments
 (0)