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
Around line 588, the example was out of sync with what the code above it was printing.
I also added a few sentences about the term "string" and how it relates to the concept of "text", as that was left a bit vague in the original.
Copy file name to clipboardExpand all lines: data/part-1/3-reading-input.md
+17-14Lines changed: 17 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ hidden: false
19
19
</text-box>
20
20
21
21
<!-- Syöte on ohjelman käyttäjän kirjoittamaa tekstiä, jota ohjelma lukee. Syöte luetaan aina merkkijonona. Syötteen lukemiseen käytetään Javan valmista `Scanner`-apuvälinettä. Apuväline tuodaan ohjelman käyttöön lisäämällä komento `import java.util.Scanner;` ennen pääohjelmarungon aloitusta (`public class` ...), ja itse apuväline luodaan komennolla `Scanner lukija = new Scanner(System.in);`. -->
22
-
Input is text written by the user, which the program reads. Input is always read as a string. For reading input, we use the `Scanner` tool that comes with Java. The tool can be imported for use in a program by adding the command `import java.util.Scanner;` before the beginning of the main program's frame (`public class` ...). The tool itself is created with `Scanner scanner = new Scanner(System.in);`.
22
+
Input is text written by the user, which the program reads. Input is always read as a string of characters, or text. For reading input, we use the `Scanner` tool that comes with Java. The tool can be imported for use in a program by adding the command `import java.util.Scanner;` before the beginning of the main program's frame (`public class` ...). The tool itself is created with `Scanner scanner = new Scanner(System.in);`.
23
23
24
24
```java
25
25
importjava.util.Scanner;
@@ -36,7 +36,7 @@ public class Program {
36
36
```
37
37
38
38
<!-- Alla on esitelty ohjelma, joka kysyy käyttäjältä syötettä, lukee käyttäjän syöttämän merkkijonon, ja lopulta tulostaa käyttäjän syöttämän merkkijonon. -->
39
-
Below is an example of a program, which asks for user input, reads the string entered by the user, and then prints it.
39
+
Below is an example of a program which asks for user input, reads the string entered by the user, and then prints it.
40
40
41
41
```java
42
42
// Introduce the scanner tool used for reading user input
@@ -62,7 +62,7 @@ public class Program {
62
62
```
63
63
64
64
<!-- Tarkemmin ottaen lukeminen tapahtuu `lukija`-apuvälineeseen liittyvällä komennolla `nextLine()`. Kutsu `lukija.nextLine()` jää odottamaan käyttäjän kirjoittamaa merkkijonoa. Kun käyttäjä syöttää merkkijonon ja painaa enteriä, käyttäjän syöttämä merkkijono asetetaan _merkkijonotyyppiseen muuttujaan_ (tässä muuttujan nimi on `viesti`). Muuttujaan `viesti` voi viitata ohjelmasta myöhemmin -- yllä olevassa esimerkissä muuttujaan `viesti` viitataan tulostuskomennossa. -->
65
-
More precisely input is read with the `scanner`-too's `nextLine()` command. The call `scanner.nextLine()`is left waiting for the user to write something. When user writes something and presses enter, the provided string is assigned to a __string variable__ (in this case `message`). The program is then able to reference the variable `message` later on -- in the example above, the variable `message` is referenced in the print command.
65
+
More precisely, input is read with the `scanner` tool's `nextLine()` command. The call `scanner.nextLine()`waits for the user to write something. When the user writes something and presses enter, the provided string (text) is assigned to a __string variable__ (in this case `message`). The program is then able to reference the variable `message` later on -- in the example above, the variable `message` is referenced in the print command.
66
66
67
67
<!-- Kun ohjelma käynnistetään, tulostus on esimerkiksi seuraavanlainen. Alla olevassa esimerkissä käyttäjä on syöttänyt tekstin "Hei maailma" -- esimerkeissä käyttäjän syöttämät tekstit merkitään punaisella. -->
68
68
When the program is run, its output can look like the example below. In this example, the user has written the text "Hello world" -- user input is marked with red in the sample examples.
@@ -83,7 +83,7 @@ The video below shows the process of making a program that reads user input. Wat
<!-- Kirjoita ohjelma, joka pyytää käyttäjää kirjoittamaan merkkijonon. Kun käyttäjä on syöttänyt merkkijonon (eli kirjoittanut tekstin sekä painanut enter-näppäintä), ohjelman tulee tulostaa käyttäjän syöttämä merkkijono. -->
86
-
Write a program that asks the user to write a string. When the user has given a string (i.e., written some text and pressed the enter key), the program must print the string provided by the user.
86
+
Write a program that asks the user to write a string. When the user has given a string (that is, written some text and pressed the enter key), the program must print the string provided by the user.
87
87
88
88
<!-- Tehtäväpohjan mukana tulee runko, joka sisältää Scanner-apuvälineen luomisen. -->
89
89
The exercise template comes with a program frame that includes the creation of a Scanner tool.
@@ -127,16 +127,18 @@ Once upon a time...
127
127
</programming-exercise>
128
128
129
129
<!-- Otetaan seuraavaksi askel taaksepäin ja tarkastellaan mitä ihmettä edellä käytetty `String viesti = ...` oikein tarkoittaa. -->
130
-
Let's next take a step back, and examine what on earth `String message = ...` even means.
130
+
Next up, let's take a step back, and examine what on earth `String message = ...` even means.
131
131
132
132
133
133
## Fundamentals of Strings
134
134
135
+
As you might have noticed, in programming we refer to "strings" rather than "text". The term "string" is shorthand for "string of characters" which describes how the computer sees text on a more fundamental level: as a sequence of individual characters.
136
+
135
137
<!-- Olemme käyttäneet merkkijonoja kahdella tapaa. Tulostuskomentoa harjoiteltaessa annoimme tulostettavan merkkijonon hipsuissa tulostuskomennolle, kun taas syötteen lukemista harjoiteltaessa luettu merkkijono tallennettiin muuttujaan. -->
136
138
We've so far used strings in two ways. When practicing the print command, we passed the string to be printed to the print command in quotation marks, and when practicing reading input, we saved the string we read to a variable.
137
139
138
140
<!-- Muuttujat ovat käytännössä nimettyjä lokeroita, jotka sisältävät tietyn tyyppistä tietoa ja joilla on nimi. Merkkijonomuuttuja esitellään ohjelmassa kertomalla muuttujan tyyppi (`String`) ja muuttujan nimi (esimerkiksi `mjono`). Muuttujan esittelyn yhteydessä muuttujaan asetetaan tyypillisesti myös arvo. Arvon asettaminen tapahtuu muuttujan esittelyä seuraavalla yhtäsuuruusmerkillä, jonka jälkeen tulee arvo sekä puolipiste. -->
139
-
In practice, variables are named containers that contain a certain type of information and have a name. A string variable is declared in a program by stating the type of the variable (`String`) and its name (`myString`, for instance). Typically a variable is also assigned a value during it's declaration. You can assign a value by following the declaration with an equals sign followed by the value and a semicolon.
141
+
In practice, variables are named containers that contain information of some specified type and have a name. A string variable is declared in a program by stating the type of the variable (`String`) and its name (`myString`, for instance). Typically a variable is also assigned a value during its declaration. You can assign a value by following the declaration with an equals sign followed by the value and a semicolon.
140
142
141
143
<!-- Merkkijonomuotoinen muuttuja nimeltä `viesti`, jonka arvona on merkkijono "Hei maailma!", luodaan seuraavasti. -->
142
144
A string variable called `message` that is assigned the value "Hello world!" is declared like this:
@@ -268,7 +270,7 @@ NB! When using the `System.out.println` -command, do not pass the string "Ada L
268
270
## Reading Strings
269
271
270
272
<!-- Lukemiseen käytettävä komento `lukija.nextLine();` lukee käyttäjän syötteen ja palauttaa merkkijonon. Mikäli merkkijonoa halutaan käyttää ohjelmassa, tulee se säilöä merkkijonomuuttujaan -- `String viesti = lukija.nextLine();`. Muuttujassa olevaa arvoa voi käyttää monta kertaa. Alla olevassa esimerkissä käyttäjän syöttämä viesti tulostetaan kahteen kertaan. -->
271
-
The `reader.nextLine();` command used for reading user input reads the user's input and *returns* a string. If we then want to use the string in the program, it must be saved to a string variable -- `String message = scanner.nextLine();`. A value saved to a variable can be used repeatedly. In the example below, the user input is printed twice.
273
+
The `reader.nextLine();` command reads the user's input and *returns* a string. If we then want to use the string in the program, it must be saved to a string variable -- `String message = scanner.nextLine();`. A value saved to a variable can be used repeatedly. In the example below, the user input is printed twice.
272
274
273
275
```java
274
276
//Introduce the Scanner tool used for reading
@@ -308,10 +310,10 @@ This will be printed twice...
308
310
<programming-exercisename='Message three times'tmcname='part01-Part01_07.MessageThreeTimes'>
309
311
310
312
<!-- Kirjoita ohjelma, joka pyytää käyttäjää kirjoittamaan merkkijonon. Kun käyttäjä on syöttänyt merkkijonon (eli kirjoittanut tekstin sekä painanut enter-näppäintä), ohjelman tulee tulostaa käyttäjän syöttämä merkkijono kolme kertaa (voit käyttää System.out.println-komentoa useampaan kertaan). -->
311
-
Write a program that asks the user to write a string. When the user has given a string (i.e., written some text and pressed enter), the program must print the user's string three times (you can use the System.out.println - command multiple times).
313
+
Write a program that asks the user to write a string. When the user has given a string (that is, written some text and pressed enter), the program must print the user's string three times (you can use the `System.out.println` command multiple times).
312
314
313
315
<!-- Tehtäväpohjan mukana tulee runko, joka sisältää Scanner-apuvälineen luomisen. -->
314
-
The exercise template comes with a program frame that includes the creation of a Scanner tool.
316
+
The exercise template already includes the code that creates the `Scanner` tool.
315
317
316
318
```java
317
319
importjava.util.Scanner;
@@ -395,7 +397,7 @@ You wrote this
395
397
Write a program that asks the user for their name by prompting them with the message "What's your name?". When the user writes their name, the program has to print "Hi " followed by the user's name.
396
398
397
399
<!-- Tehtäväpohjan mukana tulee runko, joka sisältää Scanner-apuvälineen luomisen. -->
398
-
The exercise template comes with a program frame that includes the creation of a Scanner helper tool.
400
+
The exercise template already includes the code that creates the `Scanner` tool.
399
401
400
402
```java
401
403
importjava.util.Scanner;
@@ -508,7 +510,7 @@ Thanks for sharing!
508
510
</sample-output>
509
511
510
512
<!-- Tehtäväpohjan mukana tulee runko, joka sisältää Scanner-apuvälineen luomisen. -->
511
-
The exercise template comes with a program frame that includes the creation of a Scanner tool.
513
+
The exercise template already includes the code that creates the `Scanner` tool.
512
514
513
515
```java
514
516
importjava.util.Scanner;
@@ -589,8 +591,9 @@ Write the second string:
589
591
**two**
590
592
Write the third string:
591
593
**three**
592
-
Last string you wrote was three, which was preceded by
593
-
two. The first string was one.
594
+
Last string you wrote was three, which
595
+
was preceded by two.
596
+
The first string was one.
594
597
All together: onetwothree
595
598
596
599
</sample-output>
@@ -623,7 +626,7 @@ Perhaps Bob will not be a builder forever.
623
626
</sample-output>
624
627
625
628
<!-- Tehtäväpohjan mukana tulee runko, joka sisältää Scanner-apuvälineen luomisen. -->
626
-
The exercise template comes with a program frame that includes the creation of a Scanner tool.
629
+
The exercise template already includes the code that creates the `Scanner` tool.
0 commit comments