Skip to content

Commit c3c1368

Browse files
committed
add text blocks
1 parent bf333e7 commit c3c1368

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

chapter01-basic_types.jsh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,27 @@ System.out.println(intValue);
5858
// that are object but considered as built-in by the compiler
5959

6060
// ### String
61-
// String that stores a text (a sequence of characters)
61+
// A String that stores a text (a sequence of characters) is delimited
62+
// by two doublequotes
6263
var text = "hello";
64+
System.out.println(text);
65+
66+
// a String can also span several lines, it's called a __text block__
67+
// and starts and ends with 3 double quotes
68+
var multilineText = """
69+
This is
70+
a multilines string
71+
""";
72+
System.out.println(multilineText);
73+
74+
// The indentation is determined by the alignment compared to position of the last """
75+
// By example, to have an indentation of two spaces
76+
var multilineText = """
77+
This is
78+
a multilines string
79+
indented by two spaces
80+
""";
81+
System.out.println(multilineText);
6382

6483
// Strings have a lot of methods, here is some of them
6584
// length of a String
@@ -69,6 +88,9 @@ System.out.println("hello".length());
6988
System.out.println("hello".toUpperCase());
7089
System.out.println("hello".toLowerCase());
7190

91+
// repeat the same pattern
92+
System.out.println("|*|".repeat(3));
93+
7294
// char at an index (starting with index 0)
7395
System.out.println("hello".charAt(0));
7496

guide/chapter01-basic_types.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,32 @@ All other types are objects, there are two special types, String and arrays
7272
that are object but considered as built-in by the compiler
7373

7474
### String
75-
String that stores a text (a sequence of characters)
75+
A String that stores a text (a sequence of characters) is delimited
76+
by two doublequotes
7677
```java
7778
var text = "hello";
79+
System.out.println(text);
80+
```
81+
82+
a String can also span several lines, it's called a __text block__
83+
and starts and ends with 3 double quotes
84+
```java
85+
var multilineText = """
86+
This is
87+
a multilines string
88+
""";
89+
System.out.println(multilineText);
90+
```
91+
92+
The indentation is determined by the alignment compared to position of the last """
93+
By example, to have an indentation of two spaces
94+
```java
95+
var multilineText = """
96+
This is
97+
a multilines string
98+
indented by two spaces
99+
""";
100+
System.out.println(multilineText);
78101
```
79102

80103
Strings have a lot of methods, here is some of them
@@ -89,6 +112,11 @@ System.out.println("hello".toUpperCase());
89112
System.out.println("hello".toLowerCase());
90113
```
91114

115+
repeat the same pattern
116+
```java
117+
System.out.println("|*|".repeat(3));
118+
```
119+
92120
char at an index (starting with index 0)
93121
```java
94122
System.out.println("hello".charAt(0));

jupyter/chapter01-basic_types.ipynb

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,43 @@
146146
{
147147
"cell_type": "markdown",
148148
"metadata": {},
149-
"source": ["### String\n", "String that stores a text (a sequence of characters)\n"]
149+
"source": ["### String\n", "A String that stores a text (a sequence of characters) is delimited\n", "by two doublequotes\n"]
150150
}
151151
,
152152
{
153153
"cell_type": "code",
154154
"execution_count": null,
155155
"metadata": {},
156156
"outputs": [],
157-
"source": ["var text = \"hello\"; \n"]
157+
"source": ["var text = \"hello\"; \n", "System.out.println(text);\n"]
158+
}
159+
,
160+
{
161+
"cell_type": "markdown",
162+
"metadata": {},
163+
"source": ["a String can also span several lines, it's called a __text block__\n", "and starts and ends with 3 double quotes\n"]
164+
}
165+
,
166+
{
167+
"cell_type": "code",
168+
"execution_count": null,
169+
"metadata": {},
170+
"outputs": [],
171+
"source": ["var multilineText = \"\"\"\n", " This is\n", " a multilines string\n", " \"\"\";\n", "System.out.println(multilineText);\n"]
172+
}
173+
,
174+
{
175+
"cell_type": "markdown",
176+
"metadata": {},
177+
"source": ["The indentation is determined by the alignment compared to position of the last \"\"\"\n", "By example, to have an indentation of two spaces\n"]
178+
}
179+
,
180+
{
181+
"cell_type": "code",
182+
"execution_count": null,
183+
"metadata": {},
184+
"outputs": [],
185+
"source": ["var multilineText = \"\"\"\n", " This is\n", " a multilines string\n", " indented by two spaces\n", " \"\"\";\n", "System.out.println(multilineText);\n"]
158186
}
159187
,
160188
{
@@ -185,6 +213,20 @@
185213
"source": ["System.out.println(\"hello\".toUpperCase());\n", "System.out.println(\"hello\".toLowerCase());\n"]
186214
}
187215
,
216+
{
217+
"cell_type": "markdown",
218+
"metadata": {},
219+
"source": ["repeat the same pattern\n"]
220+
}
221+
,
222+
{
223+
"cell_type": "code",
224+
"execution_count": null,
225+
"metadata": {},
226+
"outputs": [],
227+
"source": ["System.out.println(\"|*|\".repeat(3));\n"]
228+
}
229+
,
188230
{
189231
"cell_type": "markdown",
190232
"metadata": {},

0 commit comments

Comments
 (0)