
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Lab 12 PrintArray.java This week we’re moving on to arrays. Today, we’ll be working on a fairly simple lab that constructs some simple int arrays and prints them to the screen. Remember that when you need to access every member of an array, a for loop is an easy way to do it. (An enhanced for loop is even easier!) 1.Write a method with the signature : public static void printArray( int[] arg ). This method should output the values of the argument array, separated by commas and wrapped in braces. Remember, the client is passing in the argument array, you don’t know what values are held inside it or even how big it is yet! An example:
[ 0, 1, 2, 3, 4 ] The array in this case has length 5 and arg[i] == i for every index i.
[ 1, 1, 2, 3, 5, 8, 13, 21] I recommend creating a new int array (I usually call mine result), load in the value 1 for the 0th and 1st elements, then- inside a for loop- make sure the ith element is the sum of the previous two.