VERIFIED ANSWERS
\Q\.Consider this code segment:
String one = "1";
String two = "2";
String three = "3";
String four = "4";
ArrayList<String> aList = new ArrayList<String>();
aList.add(one);
aList.add(two);
aList.add(three);
aList.add(four);
What output is printed by the following statements?
aList.remove(1);
aList.add("5");
System.out.println(aList.get(1));
an error occurs
1
2
,3
none of these
5
4 - ANSWERS✔-3
\Q\.Consider the following code segment:
int w = 0;
for (int x = 0; x < 5; x++)
{
w = -1;
for (int y = 1; y < x; y++)
{
w = w + y;
}
}
System.out.println(w);
What value is printed?
1
2
0
4
-1
None of these
5
,3
8
6
7 - ANSWERS✔-5
\Q\.Consider your lab assignment when reviewing the following code that will be placed in the
CopyingJeroo class:
public void atFlower()
{
if (this.seesFlower(HERE))
{
copier.plant();
this.pick();
}
}
What would happen if this code was integrated in your solution?
The image would be removed from both islands.
The image would only be on the first island.
The image would be present on both islands.
The image would be created on the second island and removed from the first island. -
ANSWERS✔-The image would be created on the second island and removed from the first
island.
\Q\.Consider this code segment:
, boolean x = false;
boolean y = true;
boolean z = true;
System.out.println( (x || !y) && (!x || z) );
What value is printed?
Nothing, there is a syntax error
false
true - ANSWERS✔-false
\Q\.Suppose I have written the following code:
List earlyTimes = new ArrayList();
earlyTimes.add("1pm");
List otherTimes = new ArrayList();
otherTimes.add("1pm");
if (/* missing condition */)
{
System.out.println("You look great!"); //indicated line
}
Which of the following conditions will cause the indicated line to be executed?
earlyTimes.equals("1pm")