Skip to content

Commit d86b785

Browse files
authored
Merge pull request #387 from DieuMerci225/chapter3.5
added a parsons problem for section 3.5
2 parents 58a9612 + ccd1878 commit d86b785

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

source/ch3_javadatatypes.ptx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,48 @@ public class HistoArray {
967967
<p>
968968
The main difference between <xref ref="java-array" text="type-global"/> and <xref ref="java-histogram" text="type-global"/> 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.
969969
</p>
970+
971+
<exercise xml:id="java-arrays-parsons-exercise" label="java-arrays-parsons">
972+
<statement>
973+
<p>
974+
Construct a short Java program that creates an array of three integers,
975+
changes the first value, and prints it. Drag the blocks into the correct order on the right.
976+
</p>
977+
</statement>
978+
<blocks>
979+
<block order="1">
980+
<cline>public class ArrayExample {</cline>
981+
<cline> public static void main(String[] args) {</cline>
982+
</block>
983+
984+
<block order="2">
985+
<choice correct="yes">
986+
<cline> Integer[] nums = {1, 2, 3};</cline>
987+
</choice>
988+
<choice correct="no">
989+
<cline> Integer[] nums = (1, 2, 3);</cline>
990+
</choice>
991+
</block>
992+
993+
<block order="3">
994+
<choice correct="yes">
995+
<cline> nums[0] = 5;</cline>
996+
</choice>
997+
<choice correct="no">
998+
<cline> nums(0) = 5;</cline>
999+
</choice>
1000+
</block>
1001+
1002+
<block order="4">
1003+
<cline> System.out.println(nums[0]);</cline>
1004+
</block>
1005+
1006+
<block order="5">
1007+
<cline> }</cline>
1008+
<cline>}</cline>
1009+
</block>
1010+
</blocks>
1011+
</exercise>
9701012
</section>
9711013

9721014
<section xml:id="dictionary">

0 commit comments

Comments
 (0)