Skip to content

Commit 99b99c0

Browse files
committed
add listing
1 parent ec32254 commit 99b99c0

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,8 @@ public class Histo {
780780
As was said at the outset of this section, we are going to use Java <c>ArrayLists</c> because they are easier to use and more closely match the way that Python lists behave. However, if you look at Java code on the internet or even in your core Java books you are going to see examples of something called an array. In fact, you have already seen one example of an array declared in the &#x2018;Hello World&#x2019; program. Let's rewrite this program to use primitive arrays rather than array lists.
781781
</p>
782782

783-
784-
<program xml:id="java-array" interactive="activecode" language="java" datafile="test.dat">
783+
<listing xml:id="java-array">
784+
<program interactive="activecode" language="java" datafile="test.dat">
785785
<code>
786786
import java.util.Scanner;
787787
import java.io.File;
@@ -812,6 +812,7 @@ public class HistoArray {
812812
}
813813
</code> <tests> </tests>
814814
</program>
815+
</listing>
815816

816817
<p>
817818
The main difference between this example and the previous example is that we declare <c>count</c> to be an <c>Array</c> of integers. We also can initialize short arrays directly using the syntax shown here: <c>Integer[] count = {0,0,0,0,0,0,0,0,0,0}</c>Then notice that we can use the square bracket notation <c>count[idx]</c> to index into an array.

0 commit comments

Comments
 (0)