What is y after the following for loop statement is executed?

```
int y = 0;
for (int i = 0; i < 10; ++i) {
y += 1;
}
```

A. 9
B. 10
C. 11
D. 12

B. 10
Before the loop, y is 0. The loop is executed 10 times. Each time, 1 is added to y. So, after the loop is finished, y is 10. The correct answer is (B).

Computer Science & Information Technology

You might also like to view...

Explain how an aggregate function differs from a calculated field

What will be an ideal response?

Computer Science & Information Technology

In this exercise, you will create a Salary Sur- vey application that is similar to the one you created in Exercise 16.12. This application includes an ArrayList that has already been added for you, to contain the salary ranges for use by an Iterator. Note that the salary ranges are for whole dollar amounts—the amount of cents in the user’s salary is truncated before the salary is placed in a specific range. You will use the Iterator with a while statement to replace the for statement that is used in Tutorial 16 (Fig. 19.56).


a) Copying the template to your working directory. Copy the C:Examples Tutorial19ExercisesModifiedSalarySurvey directory to your C:SimplyJava directory.
b) Opening the template file. Open the SalarySurvey.java file in your text editor.
c) Clearing the JTextArea from previous output. Find the showTotalsJButtonAc- tionPerformed method, which begins at line 174. Inside the showTotalsJBut- tonActionPerformed method, clear the Survey results: JTextArea’s text.
d) Adding a header to the output. The first portion of your application’s output is the header. Use method append to add the header as a String to the Survey results: JTextArea (surveyResultsJTextArea).
e) Creating a counter variable. ArrayList rangesArrayList contains each range as a String. In the next step, you will create an Iterator to cycle through each element in this ArrayList. However, you will still need to use a counter to access the number of results for the current range. Declare counter variable i and

Computer Science & Information Technology