CS 10: Introduction to Computer Programming

In-Class Examination I

Open-Book, 75 minutes, Spring 1997

General Instructions

Please put your answer to each question on its page. The examination is designed to determine how well you know the material. Your goal is to get as many points as possible (out of a possible 100 points). Please keep this goal in mind as you budget your time. 

Read each question carefully. Make sure that you clearly understand a question before answering it. You may wish to work out an answer on scratch paper before writing it on your answer page; answers that are difficult to read may lose points for that reason. 


Name:  
Perm:  

Question  Value  Score 
1  10 
2  10 
3  10 
4  10 
5  10 
6  10 
7  10 
8  10 
9  10 
10  10 
Total  100 


1. What is the output of the following code fragment?  2. Convert each of the following using an assignment operator (e.g., +=, -=, *=, /=, %=).  If this cannot be done, say "It can't be done".  3. Convert  the following  while loop fragment to an equivalent  for loop.  If it can't be done, say "It can't be done".  4. Convert  the following  for loop fragment to an equivalent  while loop.  If it can't be done, say "It can't be done".  5. Convert  the following code using a  switch statement. The variable  x is an  int.  6. What is the output of the following code fragment?  7. Convert  the following code fragment to an equivalent one that does not use a  continue.  Draw a picture of the result.  8. Convert  the following nested  if statements to one that uses boolean operators.  If it can't be done, say "It can't be done".  9. What is the output of the following code fragment?  10. Give the Java code for an applet that draws a solid blue rectangle of size 35 X 35 pixels wherever the user clicks on the applet.  The applet should be empty until a mouse click occurs.