1: |
|
2: | Consider the following array: private int[] numbers = { 10,5,3,15} ;
|
3: | A class contains the following array declaration: private int[] heights = new int[3];
Is this a valid statement? What will happen when this line is executed? |
4: | Why is it not a good idea to use an array to represent accounts of a real world bank? |
5: | Consider the following array declaration (same as in question 2): private int[] numbers = { 10,5,3,15} ; A fellow programmer has written the following method for retrieving values from the array: int GetNumber(int index) { return numbers[index]; } Adjust for the zero-based array index so that GetNumber(1) will return the first element value of numbers instead of the second element value, as is the case with the currently shown method. |
6: | What is wrong with the following array declaration? byte [] ages = new byte [4] { 10, 34, 12, 19, 21, 56} ; |
7: | Write a method called DisplayArray that accepts an array reference of base type int. The method must be able to print the values of the array object referenced by the argument onscreen, regardless of the array length. |
8: | Write a method with the following header: int [] AddNumber(int [] tempArray, int num) that will add num to every element of tempArray and return this array back to the caller. |
9: | Consider the following two declarations: int [] myNumbers = { 2,4,6,8} ; int [] yourNumbers; Suppose that we assign myNumbers to yourNumbers and add 10 to the first element of yourNumbers, as in the following lines yourNumbers = myNumbers; yourNumbers[0] += 10; What is the value of myNumbers[0] after these statements have been executed? Explain what is going on. |
10: | What is the fundamental difference between cloning an array with the array's Clone method and simply assigning the array variable value to another array variable? |
11: | Consider the two arrays from question 9, myNumbers and yourNumbers. Suppose each array variable references a different array object. Both these array objects contain exactly the same number of array elements and each pair of corresponding array elements have the same value. Will the following comparison be true or false? Explain why. (MyNumbers == YourNumbers) |
12: | Your program contains a class called Planet. You are writing another class called SolarSystem, which in this case must consist of 10 planets. You want to represent the 10 planets in an array of 10 planets. Write the declaration you must insert into the SolarSystem class to enable the representation of the 10 planets. |