diff --git a/source/ch3_javadatatypes.ptx b/source/ch3_javadatatypes.ptx index df08c4a..f348eb0 100644 --- a/source/ch3_javadatatypes.ptx +++ b/source/ch3_javadatatypes.ptx @@ -967,6 +967,48 @@ public class HistoArray {

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

+ + + +

+ Construct a short Java program that creates an array of three integers, + changes the first value, and prints it. Drag the blocks into the correct order on the right. +

+
+ + + public class ArrayExample { + public static void main(String[] args) { + + + + + Integer[] nums = {1, 2, 3}; + + + Integer[] nums = (1, 2, 3); + + + + + + nums[0] = 5; + + + nums(0) = 5; + + + + + System.out.println(nums[0]); + + + + } + } + + +