CS 1401, Quiz #2

Date: Wednesday, September 6, 2006
Class section (9:30 am or 11:30 am): _______________________________

1. For each of the following strings, write "yes" or "no" depending on whether the string is a legal names of a Java variable.; if your answer is "no", briefly explain why.

September5 yes

5September no: does not start with a letter

September 5 no: has a blank space inside

September_5 yes

September$ yes (but not recommended)

2. Translate the following sequence of Java statements into English; show, step by step, what will happen after each of these statements.

double grade;

declare a new variable of type double; 
its name is grade, its value is undefined
   --------------
  |      ?       |
   --------------
       grade
grade = 3.0;
to the variable grade, we assign a value 3.0
   --------------
  |     3.0      |
   --------------
       grade
grade = grade + 1.0;
we add 1.0 to the previous value of the variable grade, and assign the
result to the same variable
   --------------
  |     4.0      |
   --------------
       grade
3. What is the result of the following Java operations:

9 / 5 the result is 1

9.0 / 5.0 the result is 1.8

9 % 5 the result is 4

-9 % 5 the result is -4