|
|
(17 intermediate revisions by 7 users not shown) |
Line 1: |
Line 1: |
− | {{1010Topic|Introduction=This section has some review questions and exercise to help you review this section.|Overview=Learn how to try out your programming skills with these exercises and questions.}} | + | {{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 style="background-color:green; color:white;">
| + | # [[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 style="background-color:green; color:white;">
| + | |
− | 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)
| + | |
− | | + | |
− | Does the second statement of following code copy an array?
| + | |
− | <pre style="background-color:green; color:white;">
| + | |
− | | + | |
− | int array1[]={2,4}
| + | |
− | int array2[]=array1;
| + | |
− | </pre>
| + | |
− | [[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 style="background-color:green; color:white;">
| + | |
− | 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 style="background-color:green; color:white;">
| + | |
− | 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 populate an array?
| + | |
− | | + | |
− | [[Chapter 8, exercise 3 answer|Answer]]
| + | |
− | | + | |
− | =Exercise 4=
| + | |
− | (ABU)
| + | |
− | | + | |
− | Write a program to copy an 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]]
| + | |