Difference between revisions of "Arrays Review Questions and Exercises"
(→Question 5) |
(→Question 6) |
||
Line 53: | Line 53: | ||
=Question 6= | =Question 6= | ||
+ | What does the following piece of code print to the screen? | ||
+ | |||
+ | <pre> | ||
+ | String s = "Gello"; | ||
+ | String h = new String [10]; | ||
+ | |||
+ | h[10] = s; | ||
+ | s = "Jello"; | ||
+ | System.out.println(h[10]); | ||
+ | </pre> | ||
+ | |||
[[Chapter 8, question 6 answer|Answer]] | [[Chapter 8, question 6 answer|Answer]] | ||
+ | |||
=Exercise 1= | =Exercise 1= | ||
(Andrew) | (Andrew) |
Revision as of 14:41, 20 March 2007
Contents
Question 1
(Andrew)
What is it called when you access an element outside of the bounds of an array.
Example
int i[] = new int[3]; i[4] = 3;
Question 2
(Andrew)
What is it called when a for-loop loops one iteration too many such that it passes the array's bounds.
Example:
int j; int array[] = new int[3]; for (j = 0; j <= 3; j++) { array[j] = 0; }
Question 3
(ABU)
When you copy one array do you need to copy each element of array? or just have to copy the name of array?
Question 4
(ABU)
Can you extend the size of array by adding the size of array with the existing one?
Question 5
Does the following piece of code change the value of i to "Hey"?
String i = "Hello"; String array[] = new String [20]; array[10] = i; array[10] = "Hey";
Question 6
What does the following piece of code print to the screen?
String s = "Gello"; String h = new String [10]; h[10] = s; s = "Jello"; System.out.println(h[10]);
Exercise 1
(Andrew)
Write a program that calculates the product of all the values in an array.
Exercise 2
(Andrew)
Write a program that finds the position of the smallest value in an array.
Exercise 3
(ABU)
Write an program to create and populating an array?
Exercise 4
(ABU)
How to copy an array and compare to array?
Exercise 5
Create a function to sort an array of integers
Exercise 6
Write a program to print all of the values in an array