Practice Bank

Fall 2006 Sample Questions (End-of-class questions).  Based upon the lecture content, examples, and reading, you should be able to do these.


Lecture 6/7:

What would be the output of the following:

----------------------------------

int i;

for(i=30; i > 0; i-=5)
{
  Console.Writeline(i);
}

Console.Writeline("Yeah!");

----------------------------------

As a hint, recall:

i-=5 --> i = i - 5

i++ --> i = i + 1
i-- --> i = i - 1
i+=2 --> i = i + 2
i-=2 --> i = i - 2

----------------------------------

Answer:

30
25
20
15
10
5
Yeah!

 

Lecture 8:

1. Declare an array to hold 2000 integers

2. Now that you've declared the integer array, write a loop that will fill the array such that the i-th cell in the array contains the value 2*i (for example, the 0-th cell contains 0, the 1-st cell contains 2, the 2-nd cell contains 4, etc... the 1998-th cell contains 3996, and the 1999-th cell contains 3998).


Sample Answers from Summer 2005 Midterm Study Session

Spring 2006 Help Sessions

Spring 2006 In-class review questions