Question: QUESTION 11 Given an array of int called scores, which of the following will access the first element of the array? A. scores[1] B. scores.length
QUESTION 11
Given an array of int called scores, which of the following will access the first element of the array?
| A. | scores[1] | |
| B. | scores.length - 1 | |
| C. | scores.length | |
| D. | scores[0] |
QUESTION 12
Which of the following will allocate memory to hold an array of 10 int values?
| A. | int scores[] = new int[9]; | |
| B. | int scores; | |
| C. | int scores[] = new int[10]; | |
| D. | int scores[]; |
QUESTION 13
Re-write the following using a for loop
int z = 99; while (z >= 12) { System.out.print("z is: "); System.out.println(z); z = z - 3; } System.out.println("done");
| A. | for (int z = 99; z >= 12; z = z - 3) { System.out.print("z is: "); } System.out.println(z); System.out.println("done"); | |
| B. | for (int z = 99; z >= 12; ++z) { System.out.print("z is: "); System.out.println(z); z = z - 3; } System.out.println("done"); | |
| C. | for (int z = 99; z >= 12; z = z - 3) System.out.print("z is: "); System.out.println(z): System.out.println("done"); | |
| D. | for (int z = 99; z >= 12; z = z - 3) { System.out.print("z is: "); System.out.println(z); } System.out.println("done"); |
QUESTION 14
What is the value of x after the following?
int x = 0; for (int i = 2; i <= 14; i = i + 3) x = x + i;
| A. | 0 | |
| B. | 26 | |
| C. | 40 | |
| D. | 57 |
QUESTION 15
Given the following class definition:
public class Foo { private int bar;
public Foo(int i) { bar = i; }
public void wah(int i) { bar = bar + i; }
public void dah() { System.out.print(bar); } }
and executing this code segment:
Foo f = new Foo(20); f.wah(10); f.dah();
What value will be output?
| A. | 0 | |
| B. | 10 | |
| C. | 20 | |
| D. | 30 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
