Skip to content

Commit c4fd0a7

Browse files
committed
added listing blocks
1 parent ec32254 commit c4fd0a7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ public class HistoArray {
829829
Lets stay with a simple frequency counting example, only this time we will count the frequency of words in a document. A simple Python program for this job could look like this:
830830
</p>
831831

832-
833-
<program xml:id="python-input-file2" interactive="activecode" language="python">
832+
<listing xml:id="python-word-count">
833+
<program interactive="activecode" language="python">
834834
<code>
835835
def main():
836836
data = open('alice30.txt')
@@ -845,11 +845,14 @@ def main():
845845
main()
846846
</code> <tests> </tests>
847847
</program>
848+
</listing>
848849

849850
<p>
850851
This program reads the file <c>alice30.txt</c> (which follows), and it then splits it into a list of words. Next it creates a dictionary called <c>count</c> which maps each word to the number of times that word occurs in the text. Finally, it prints out the words in alphabetical order along with their frequency.
851852
</p>
852853

854+
<data xml:id="datafile-alice1">
855+
<title>Data file for testing the word frequency program</title>
853856
<datafile label="datafile-alice1" filename="alice30.txt" editable="no" cols="30" rows="15">
854857
<pre>
855858
Down, down, down. Would the fall NEVER
@@ -872,12 +875,13 @@ main()
872875
nice grand words to say.)
873876
</pre>
874877
</datafile>
878+
</data>
875879
<p>
876880
Notice that the structure of the program is very similar to the numeric histogram program.
877881
</p>
878882

879-
880-
<program xml:id="java-use-input-file" interactive="activecode" language="java" datafile="alice30.txt">
883+
<listing xml:id="java-word-count">
884+
<program interactive="activecode" language="java" datafile="alice30.txt">
881885
<code>
882886
import java.util.Scanner;
883887
import java.util.ArrayList;
@@ -915,6 +919,7 @@ public class HistoMap {
915919
}
916920
</code> <tests> </tests>
917921
</program>
922+
</listing>
918923

919924
<p>
920925
Improve the program above to remove the punctuation.

0 commit comments

Comments
 (0)