The Knowledge Of Sauron's Minions
From Huben's Wiki
(→(D) Multitudinous Variables) |
|||
Line 69: | Line 69: | ||
anArray = [8 2 5] | anArray = [8 2 5] | ||
− | In math, we would use subscripts to specify which of the numbers to select, subscripts from 1 to 3. But '''in Java subscripts start at zero''' and '''subscripts are numbers within square brackets'''. | + | In math, we would use subscripts to specify which of the numbers to select, subscripts from 1 to 3. But '''in Java subscripts start at zero''' and '''subscripts are numbers within square brackets'''. Each number in an array is called an '''element'''. |
# Add 'System.out.println( anArray[0] + anArray[1] + anArray[2] );' into main(). What does this do? | # Add 'System.out.println( anArray[0] + anArray[1] + anArray[2] );' into main(). What does this do? | ||
# You might notice that the array was initialized to three values by placing the set of values in curly braces. Where else have we used curly braces? | # You might notice that the array was initialized to three values by placing the set of values in curly braces. Where else have we used curly braces? | ||
+ | # What is element 2 of the array? | ||
# Add another value to the array by putting another number within the curly braces. | # Add another value to the array by putting another number within the curly braces. | ||
# Change one of the array values by adding this line in main(): 'anArray[1] = -3;'. Can you write a set of println() to show all the array values, and see which has changed? | # Change one of the array values by adding this line in main(): 'anArray[1] = -3;'. Can you write a set of println() to show all the array values, and see which has changed? | ||
# Look ye at the signature of main(). Where is the array in it? What is it an array of? | # Look ye at the signature of main(). Where is the array in it? What is it an array of? |