Java Reference
In-Depth Information
18. Which of the following is a layout manager constant?
a. center b. Center
c. CENTER d. c.Center
19. Given the following partial program, what displays when the code is executed?
int first = 0;
for (int i = 0; i<5; i++)
{
int second = 0;
first += 1;
for (int j = 1; j<4; j++)
{
second += first;
System.out.println(first + second);
}
}
20. In the following for statements, determine how many times the counter-
controlled loop will be executed. The answer may be zero, any positive
integer, or infinite:
1. for (int i = 0; i<50; i++)
2. for (int j = 10; j>0; j--)
3. for (int k = 0; k<100; k+=5)
4. for (int m = 7; m<9; m++);
21. Determine how many lines will print in the following nested loop:
for (int count = 1; count<15; count++)
for (int nextCount = 1; nextCount<15; nextCount++)
System.out.println(“This line will print”);
22. List what will display when each line of the following code is executed. In the
example, the first line of code declares and constructs an array of ints.
Because no values have been assigned, the next line results in the display of a
zero, which is the value stored at the zero element of the array. Assume the
code progresses sequentially from line 1 through 19.
1. int[] myArray = new int[10];
2. System.out.println(myArray[0]);
3. myArray[1] = 28;
4. System.out.println(myArray[1]);
5. myArray[2] = myArray[1];
6. System.out.println(myArray[2]);
7. myArray[3] = ++myArray[2];
8. System.out.println(myArray[3]);
9. myArray[4] = myArray[1]--;
(continued)
Search WWH ::




Custom Search