Difference between revisions of "Arrays Review Questions and Exercises"

From CompSciWiki
Jump to: navigation, search
m (Removed old questions. Added PAD.)
 
(30 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{1010Chapter|Introduction=This section has some review questions and exercise to help you review this section.|Overview=}}
+
{{Template:1010Topic
=Question 1=
+
|Chapter_TOC=[[Arrays]]
(Andrew)
+
|Previous=[[Processing Arrays (using for loops)]]
 +
|Next=[[More With Arrays]]
 +
|Body=
  
What is it called when you access an element outside of the bounds of an array.
+
= Try these Program a Day Questions: =
  
Example
+
# [[Creating an Array]]
<pre>
+
# [[Printing an Array]]
    int i[] = new int[3];
+
# [[Equating Two Arrays]]
    i[4] = 3;
+
# [[Passing Arrays]]
</pre>
+
# [[Fibonacci Numbers]]
[[Chapter 8, question 1 answer|Answer]]
+
  
=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:
+
<pre>
+
    int j;
+
    int array[] = new int[3];
+
    for (j = 0; j <= 3; j++) {
+
        array[j] = 0;
+
    }
+
</pre>
+
[[Chapter 8, question 2 answer|Answer]]
+
 
+
=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?
+
 
+
[[Chapter 8, question 3 answer|Answer]]
+
 
+
=Question 4=
+
 
+
(ABU)
+
 
+
Can you extend the size of array by adding the size of array with the existing one?
+
 
+
[[Chapter 8, question 4 answer|Answer]]
+
 
+
=Question 5=
+
(Graham)
+
 
+
Does the following piece of code change the value of '''i''' to "Hey"?
+
<pre>
+
    String i = "Hello";
+
    String array[] = new String [20];
+
    array[10] = i;
+
    array[10] = "Hey";
+
</pre>
+
 
+
[[Chapter 8, question 5 answer|Answer]]
+
 
+
=Question 6=
+
(Graham)
+
 
+
What does the following piece of code print to the screen?
+
 
+
<pre>
+
    String s = "Gello";
+
    String h[] = new String [20];
+
 
+
    h[10] = s;
+
    s = "Jello";
+
    System.out.println(h[10]);
+
</pre>
+
 
+
[[Chapter 8, question 6 answer|Answer]]
+
 
+
=Exercise 1=
+
(Andrew)
+
 
+
Write a program that calculates the product of all the values in an array.
+
 
+
[[Chapter 8, exercise 1 answer|Answer]]
+
 
+
=Exercise 2=
+
(Andrew)
+
 
+
Write a program that finds the position of the smallest value in an array.
+
 
+
[[Chapter 8, exercise 2 answer|Answer]]
+
 
+
=Exercise 3=
+
(ABU)
+
 
+
Write an program to create and populating an array?
+
 
+
[[Chapter 8, exercise 3 answer|Answer]]
+
 
+
=Exercise 4=
+
(ABU)
+
 
+
How to copy an array and compare to array?
+
 
+
 
+
[[Chapter 8, exercise 4 answer|Answer]]
+
 
+
=Exercise 5=
+
(Graham)
+
 
+
Create a function to sort an array of integers
+
 
+
[[Chapter 8, exercise 5 answer|Answer]]
+
 
+
=Exercise 6=
+
(Graham)
+
 
+
Write a program to print all of the values in an array
+
 
+
[[Chapter 8, exercise 6 answer|Answer]]
+

Latest revision as of 17:02, 7 December 2011

COMP 1010 Home > Arrays


Try these Program a Day Questions:

  1. Creating an Array
  2. Printing an Array
  3. Equating Two Arrays
  4. Passing Arrays
  5. Fibonacci Numbers
Previous Page: Processing Arrays (using for loops) Next Page: More With Arrays