QUESTION 11 Given an array of int called scores, which of the following will acc
ID: 3864230 • Letter: Q
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 - 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
A.
scores[1]
B.
scores.length - 1
C.
scores.length
D.
scores[0]
Explanation / Answer
Ans11 option d
scores[0]
since the first index of array is 0.
Ans12
option c
int scores[] = new int[10];
Ans13
option d
for (int z = 99; z >= 12; z = z - 3) {
System.out.print("z is: ");
System.out.println(z);
}
System.out.println("done");
Ans 14
optionc 40
since i goes from 2 to 14 and i is incremented by 3
so different i values will be 2,5,8,11,14
and x is initially 0
so add 2+5+8+11+14 = 40
Ans15
option D 30
since
Foo f = new Foo(20); // on executing this bar=20
f.wah(10); // on executing this bar = bar + i ==> bar = 20+10 = 30
f.dah(); // this will print 30
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.