Sie sind auf Seite 1von 22

Final Exam Sample # __

Sample

Final Exam

Computer Science II Adv Final Exam Sample


Directions :: On your answer sheet, mark the letter of the best answer to each question. Each question is worth 2.5
points for a total of 100 points. Write only on your answer sheet or scratch paper. Put your test # and test ID on your
answer sheet.
QUESTION 1 xx

Which of the following LinkedList methods will change the value of a location in an LinkedList?
A. add()

B. change()

C. get()

D. set()

E. None of these

QUESTION 2 xx

Which of the following LinkedList methods will insert a new value at a location in an LinkedList?
A. add()

B. insert()

C. get()

D. set()

E. None of these

QUESTION 3 xx

What is the output?


A. one

B. onetwo

C. onetwothree

D. twothree

E. None of these

Scanner scan = new Scanner("three two one");


String strang = "";
while(scan.hasNext())
strang+=scan.next();
out.println(strang);

QUESTION 4 xx

What is the output?


A. [one, two, three]
B. [three, two, one]
C. [one]
D. [three]

LinkedList<String> aList=new LinkedList<String>();


aList.add("one");
aList.add("two");
aList.add("three");
out.println(aList);

E. [two]
QUESTION 5 xx

What is the output?


A. [one, two, three]
B. [three, two, one]
C. [one]
D. [three]

LinkedList<String> bList=new LinkedList<String>();


bList.add(0,"three");
bList.add(0,"two");
bList.add(0,"one");
out.println(bList);

E. [two]
QUESTION 6 xx

What is the output?


A. 2

B. 1

C. 0

D. 4

E. 5
QUESTION 7 xx

LinkedList<String> cList=new LinkedList<String>();


cList.add(0,"one");
cList.add("two");
cList.add(0,"three");
cList.add("four");
cList.add(0,"five");
out.println(cList.indexOf("four"));
LinkedList<String> dList=new LinkedList<String>();
dList.add(0,"one");

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

What is the output?


A. 2

B. 1

C. 0

D. 4

E. 5

dList.add("two");
dList.add(0,"three");
dList.add("four");
dList.add(1,"five");
out.println(dList.indexOf("three"));

QUESTION 8 xx

What is the output?


A.
B.
C.
D.
E.

one
two
three
four
five

LinkedList<String> eList=new LinkedList<String>();


eList.add("one");
eList.add("two");
eList.set(1,"three");
eList.add(1,"four");
eList.add(0,"four");
eList.set(3,"five");
out.println(eList.get(0));

QUESTION 9 xx

What is the output?


A.
B.
C.
D.
E.

one
two
three
four
five

LinkedList<String> fList=new LinkedList<String>();


fList.add("one");
fList.add(0,"two");
fList.set(1,"three");
fList.add(1,"four");
fList.set(1,"five");
out.println(fList.get(1));

QUESTION 10 xx

What is the output?


A.
B.
C.
D.
E.

one
two
three
four
five

LinkedList<String> gList=new LinkedList<String>();


gList.add(0,"one");
gList.set(0,"two");
gList.set(0,"three");
gList.add("four");
gList.set(0,"five");
out.println(gList.get(1));

QUESTION 11 xx

Which of the following would correctly fill blank


<1> ?
A.
B.
C.
D.
E.

charAt();
charAt(0);
substring(0);
substring(0,1);
substring(0,0);

LinkedList<String> hList=new LinkedList<String>();


hList.add(0,"one");
hList.add("two");
hList.set(0,"three");
hList.add(1,"four");
hList.set(1,"five");
char cOne = hList.get(0). <1>

QUESTION 12 xx

What is the output?


A.
B.
C.
D.
E.

1
2
3
4
5

LinkedList<Integer> iList;
iList = new LinkedList<Integer>();
iList.add(0, 1);
iList.add(2);
iList.set(0,3);
iList.add(1,4);
iList.set(0,5);
out.println(iList.get(0));

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 13 xx

What is the output?


A.
B.
C.
D.
E.

0
1
99
78
71

QUESTION 14 xx

What is the output?


A.
B.
C.
D.
E.

[99 , 8
[78 , 8
[99, 78
[8 , 78
[8 , 99

]
]
]
]
]

class It
{
public It( ) { x = 99; }
public String toString(){
return x + "";
}
private int x = 78;
}
//code in main in some class
It itOne = new It();
System.out.println(itOne);
class At
{
public At( ) { x = 99; }
public At( int y ) { x = y; }
public String toString(){
return x + " ";
}
private int x = 78;
}
//code in main in some class
LinkedList atList = new LinkedList();
atList.add( new At(8));
atList.add( new At());
System.out.println(atList);

QUESTION 15 xx

What is the output?


A. [8, 2, 5, 6, 9]
B. [2, 5, 6, 9, 8]
C. [2, 5, 6, 9, 8]
D. [2, 5, 6, 8, 9]
E. [2, 8, 5, 2, 9]

LinkedList jList = new LinkedList();


jList.add(2);
jList.add(8);
jList.add(5);
jList.add(6);
jList.add(9);
Collections.sort(jList);
out.println(jList);

QUESTION 16 xx

What is the output?


A. [2, 3, 11, 25]
B. [11, 3, 25, 2]
C. [11, 2, 25, 3]
D. [3, 11, 2, 25]

LinkedList kList = new LinkedList();


kList.add("2");
kList.add("11");
kList.add("25");
kList.add("3");
Collections.sort(kList);
out.println(kList);

E. None of these

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 17 xx

What is the output?


A. [at, up, 33]
B. [at, 33, or]
C. [at, up, or, 33]

LinkedList<String> words;
words = new LinkedList<String>();
words.add("at");
words.add("up");
words.add("or");
words.set(1, "33");
System.out.println(words);

D. [33, at, up]


E. [33, at]
QUESTION 18 xx

What is the output?


A. [2, 5, 6, 9]
B. [2, 6, 8, 9]
C. [8, 5, 6, 9]
D. [5, 6, 8, 9]

LinkedList mList = new LinkedList();


mList.add(2);
mList.add(8);
mList.add(5);
mList.add(6);
mList.add(9);
mList.remove(0);
out.println(mList);

E. [5, 6, 8]
QUESTION 19 x

What is the output?


A. [z,x,w,x,x]
B. [z,w,x,x]
C. [z,x,w,x]
D. [z,w]
E. [z,x,x,x]

LinkedList<String> stringList;
stringList = newLinkedList<String>();
stringList.add("z");
stringList.add("x");
stringList.add("x");
stringList.add("w");
stringList.add("x");
stringList.add("x");
stringList.add("x");
for(int i=0; i<stringList.size();i++)
{
if(stringList.get(i).equals("x"))
stringList.remove(i);
}
out.println(stringList);

QUESTION 20 x

What is the output?


A. [z,x,w,x,e]
B. [z,w,e]
C. [z,x,w,x]
D. [z,w,x,e]
E. [z,x,x,e]

LinkedList<String> wordList;
wordList = newLinkedList<String>();
wordList.add("z");
wordList.add("x");
wordList.add("x");
wordList.add("w");
wordList.add("x");
wordList.add("x");
wordList.add("e");
int i=0;
while(i<wordList.size())
{

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

if(wordList.get(i).equals("x"))
wordList.remove(i);
else i++;

}
out.println(wordList);

QUESTION 21xx

What is the output of //line 1?


A. 0
B. 1
C. true
D. false
E. error
QUESTION 22 xx

What is the output of //line 2?


A. [34, 11, 14]
B. [34, 34, 11, 14]
C. [11, 14, 34, 34]
D. [11, 14, 34]
E. [34, 11, 34, 14]

Set<Integer> aSet = new TreeSet<Integer>();


aSet.add(34);
out.println(aSet.add(11));
//line 1
aSet.add(34);
aSet.add(14);
out.println(aSet);

//line 2

out.println(aSet.size());

//line 3

QUESTION 23 xx

What is the output of //line 3?


A. 0
B. 1
C. 2
D. 3
E. 4

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 24 xx

What is the output?


A. 0

B. 1

C. 2

D. no output error

Collection<Integer> c = new TreeSet<Integer>();


c.add(34);
c.add(35);
out.println(c.size());

E. None of these
QUESTION 25 xx

What is the output?


Set<String> bSet = new TreeSet<String>();
bSet.add("one");
bSet.add("one");
bSet.add("three");
out.println(bSet);

A. [one, three, one]


B. [one, one, three]
C. [one, three]
D. [three]
E. [two]
QUESTION 26 xx

Which of the following best matches the runtime for TreeMap?


add()

get()

A.

O(1)

O(N)

B.

O(1)

O(1)

C.

O(N)

O(log2N)

D.

O(log2N)

O(log2N)

E.

O(log2N)

O(N)

QUESTION

27x

Which of the following interfaces must be implemented by all Objects stored as keys in a TreeMap?
A. Locatable
QUESTION

B. Sortable

C. Treeable

D. Comparable

E. TreeMapable

28x

Which of the following would correctly fill < *1 > ?


A. 45.44

Set<Double> s = new TreeSet<Double>();


s.add( < *1 > );

B. 23.1f
C. 345
D. A and B only
E. A, B, and C only
QUESTION 29xx

Which of the following would correctly fill < *1 > ?


A. map.get(line)!=null
B. map.containsKey(line)
C. map.get(person)!=null
D. map.containsKey(line)=false
E. more than one of these
QUESTION 30xx

Which of the following would correctly fill < *2 > ?


A. new Set<String>();

//Class Lines would store lines and the


//names of the people in those lines
class Lines
{
private Map<String,Set<String>> map;

public Lines()
{
map = new TreeMap<String,Set<String>>();
}
public void setPerson(String pair)
{

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

B. new TreeSet<String>();
C. new TreeSet<>();
D. new Set();
E. new TreeSet<Integer>();
QUESTION 31xx

Which of the following would correctly fill < *3 > ?


A. map.put(line,person);
B. map.put(line,map);
C. map.put(line,s);
D. map.put(s);
E. map.put(s, line);

String[] list = pair.split(" ");


String line = list[0];
String person = list[1];

QUESTION 32xx

Which of the following would correctly fill < *4 > ?


A. String key : map
B. String key : map.keySet().iterator()
C. String key : map.key()
D. String key : map.set()
E. String key : map.keySet()

Set<String> s;
if( < *1 > ){
s = map.get(line);
s.add(person);
< *3 >
}
else{
s = < *2 >
s.add(person);
< *3 >

QUESTION 33 xx

Which of the following adds and removes items according to FIFO rules?
A. stack

B. queue

C. priority queue

D. binary tree

E.

array

D. binary tree

E.

array

QUESTION 34xx

Which of the following adds and removes items according to LIFO rules?
A. stack

B. queue

C. priority queue

QUESTION 35 xx

Which of the following adds and removes items according to comparisons made by the compareTo in the Objects being stored?
A. stack

B. queue

QUESTION 36xx

What is the output of line 1?


A. [5]

B. [7]

C. [5,7]
E. None of these

D. [7,5]

QUESTION 37xx

C. priority queue

D. binary tree

E.

array

Stack<Integer> a = new Stack<Integer>();


Queue<Integer> b;
b = new LinkedList<Integer>();
a.push(7);
a.push(5);
out.println(a);
b.add(a.pop());
b.add(a.pop());
out.println(b);

//line 1
//line 2

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

What is the output of line 2?


A. []

B. [7]

C. [5,7]

D. [7,5]

E. None of these

QUESTION 38xx

What is the output of the statement on line 1?

What is the output of the statement on line 2?

Queue<Integer> c;
c = new LinkedList<Integer>();
c.add(5);
c.add(3);
c.add(9);

A. 4

out.println(c.remove());

A. 1

B. 3

C. 5

D. 9

E. -1

QUESTION 39 xx

B. 2

C. 5

D. 3

E. -1

//line 1

QUESTION 40 xx

What is the output of the statement on line 3?


A. true

B. false

C. 1

D. 0

E. -1

QUESTION 41 xx

c.add(17);
c.add(19);
out.println(c.peek());
out.println(c.isEmpty());

//line 2
//line 3

After this code segment is executed, how many elements remain in


c?
A. 2

B. 3

C. 4

D. 5

E. 0

QUESTION 42xx

What is the output?


A. 78

B. 23

C. 14
E. None of these

D. 11

QUESTION 43xx

What is the output?


A. 14 9

B. 9 5

C. 53 9
E. None of these

D. 14 53

Queue<Integer> d;
d = new LinkedList<Integer>();
d.add(23);
d.add(78);
d.add(14);
out.println(d.remove());
Queue<Integer> e;
e = new LinkedList<Integer>();
e.add(14);
e.add(9);
e.add(53);
e.add(5);
out.print(e.remove()+" ");
out.println(e.remove());

QUESTION 44 xx

What is the output?


A. 34

B. 76

C. 84
E. None of these

D. null

Stack<Integer> f = new Stack<Integer>()


f.push(84);
f.push(76);
f.push(34);
out.println(f.pop());

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 45 xx

What is the output?


A. [12,36]

B. [36,12]

C. [12]
E. None of these

D. [36]

Stack<Integer> g = new Stack<Integer>()


g.push(36);
g.pop();
g.push(12);
out.println(g);

QUESTION 46 xx

A. 12

B. 5

C. 7
E. 0

D. 9

Stack<Integer> h = new Stack<Integer>()


h.push(12);
h.pop();
h.push(5);
h.pop();
h.push(9);
h.pop();
h.push(7);
out.println(h.pop());

A. 45 87

B. 45 34

C. 45
E. None of these

D. 87 45

Stack<Integer> j = new Stack<Integer>()


j.push(34);
j.peek();
j.push(87);
out.print(j.pop()+" ");
j.push(45);
out.print(j.pop());

What is the output?

QUESTION 47xx

What is the output?

QUESTION 48 xx

What is the output of line 1?


A. 3.4

B. 1.6

C. 8.2

D. 5.2

E. 0.0

Stack<Double> k = new Stack<Double>();


k.push(1.6);
k.push(3.4);
out.println(k.pop());

QUESTION 49 xx

What is the output of line 2?


A. 3.4

B. 1.6

C. 8.2

D. 5.2

//line 1

k.push(5.2);
out.println(k.pop());

//line 2

E. 0.0
QUESTION 50xx

Which of the following statements would correctly fill <*1>?


A.
B.
C.
D.
E.

return
return
return
return
return

queue.remove();
queue.remove(0);
queue.erase(0);
queue[0].remove();
queue.set(0,0);

public class StringQueue


{
private ArrayList<String> queue;
public StringQueue(){
queue=new ArrayList<String>();
}
public void add(String x){

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 51xx

Which of the following statements would correctly fill <*2>?


A.
B.
C.
D.
E.

return
return
return
return
return

queue.get(0);
queue.get(queue.size()-1);
queue.get(1);
queue[0];
queue[queue.size()-1];

queue.add(x);
}
public String remove(){

QUESTION 52xx

<*1>

}
public String front(){

Which of the following statements would correctly fill <*3>?


A.
B.
C.
D.
E.

return
return
return
return
return

<*2>

queue.get(0);
queue.get(queue.size());
queue.get(queue.size()-1);
queue[0];
queue[queue.size()-1];

}
public String back(){
<*3>

}
public boolean isEmpty(){
<*4>

QUESTION 53xx

Which of the following statements would correctly fill <*4>?


A.
B.
C.
D.
E.

return
return
return
return
return

queue.length==0;
queue.size()==0;
queue.size==0;
queue.size;
queue.size()-1;

QUESTION 54 xx

What is the output of line 1?


A. d

B. a

C. w
E. z

D. r

QUESTION 55 xx

What is the output of line 2?


A. d

B. a

C. w
E. z

D. r

QUESTION 56 xx

What is the output of line 3?


A. d

B. a

C. w
E. z

D. r

PriorityQueue<String> pQ;
pQ = new PriorityQueue<String>();
pQ.add("z");
pQ.add("a");
out.println(pQ.remove());
pQ.add("w");
pQ.add("a");

//line 1

out.println(pQ.remove());
pQ.add("r");

//line 2

out.println(pQ.remove());

//line 3

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 57xx

If a complete tree has 3 levels, which of the following are possible node counts for the tree?
A. 9

B. 5

C. 3

D. 2

E. 11

D. 8

E. 9

QUESTION 58 xx

If a tree has a height of 8, how many levels does it have?


A. 5

B. 6

C. 7

QUESTION 59 xx

What type of tree traversal is this?


A. inorder.
B. preorder
C. postorder
D. reverse
E. none of these

private void traverse(TreeNode tree){


if(tree != null){
out.print(tree.getValue() + " ");
traverse(tree.getLeft());
traverse(tree.getRight());
}
}

QUESTION 60 xx

What type of tree traversal is this?


A. inorder.
B. preorder
C. postorder
D. reverse
E. none of these

private void traverse(TreeNode tree){


if (tree != null){
traverse(tree.getLeft());
out.print(tree.getValue() + " ");
traverse(tree.getRight());
}
}

QUESTION 61xx

What type of tree traversal is this?


A. inorder.
B. preorder
C. postorder
D. reverse
E. none of these

private void traverse(TreeNode tree){


if(tree != null){
traverse(tree.getRight());
out.print(tree.getValue() + " ");
traverse(tree.getLeft());
}
}

QUESTION 62xx

What type of tree traversal is this?


A. inorder.
B. preorder
C. postorder
D. reverse
E. none of these

private void traverse(TreeNode tree){


if(tree != null){
traverse(tree.getLeft());
traverse(tree.getRight());
out.print(tree.getValue() + " ");
}

QUESTION 63 xx

A complete binary tree will


A.
B.
C.
D.
E.

have all levels filled


have all levels full that can be and all partial levels shifted to the left
have all levels shifted to the left
never have leaves
be balanced

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 64xx

Which of the following is true for a full binary tree?


A.
B.
C.
D.
E.

the bottom most level has nothing but leaves


the bottom most level has mostly leaves
the bottom most level is almost complete
the bottom most level is nothing but parents
the bottom most level has the biggest nodes

Questions 65 67 refer to the following code.


TreeNode x = new TreeNode("10",null,null);
TreeNode y = new TreeNode("20", null,null);
TreeNode z = new TreeNode("25", x, y);
QUESTION 65xx

What is the output of the following code?


out.println(z.getValue());

A.

B.

20

C.

10

D.

25

E.

null

QUESTION 66 xx

What is the output of the following code?


out.println(z.getLeft().getValue());
A. 0

B. 20

C. 10

D. 25

E. null

D. 25

E. null

QUESTION 67xx

What is the output of the following code?


out.println(z.getRight().getValue());
A. 0

B. 20

C. 10

QUESTION 68xx

Which of the following correctly instantiates a TreeNode with the value 99 and with both references set to null?
A.
B.
C.
D.
E.

TreeNode
TreeNode
TreeNode
TreeNode
TreeNode

x
x
x
x
x

=
=
=
=
=

TreeNode(99,null,null);
TreeNode(99,-1,-1);
new TreeNode(null,null,99);
new TreeNode(99,0,0);
new TreeNode(null,99,null);

QUESTION 69 xx

Each node in a threaded tree will have


A.
B.
C.
D.
E.

a left child and a right child only.


at least two children.
one parent
one child.
a parent and at most two children.

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 70x

Given a complete tree with 4 levels, how many leaves could this tree have?

I. 4
II. 5
III. 12

A. I only
B. II only
C. III only
D. I and II only
E. I and III only
QUESTION 71xx

How many nodes would a full tree with 4 levels have?

A. 15
B. 16
C. 32
D. 31
E. 63
QUESTION 72 xx

Which of the following is true for a heap that stores the minimum priority value at the root?
A.
B.
C.
D.
E.

The root will be the item with the greatest value in the tree.
The nodes from the root down are in sorted order by level.
The root will be the item with the lowest value in the tree.
The nodes from the root down are in sorted order by branch.
none of these answers are correct.

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 73 xx

Which of the following could replace <*1> in the code to


the right so that method isIt would determine if parameter
t has two children?
A. t.getRight()==null && t.getLeft()==null
B. t.getRight()!=null && t.getLeft()!=null
C. t.getRight()==null || t.getLeft()==null
D. t==null
E. more than one of these
QUESTION 74 xx

What is method run attempting to determine about a tree?


A. if the tree is empty
B. the number of children in the tree

public boolean isIt(TreeNode t)


{
return ( <*1> );
}
public int run(TreeNode t)
{
if(t==null) return 0;
if(isIt(t)) return 1 +
run(t.getLeft()) +
run(t.getRight());
return run(t.getLeft()) +
run(t.getRight());
}
}

C. the number of leaves in the tree


D. the number of parents in the tree
E. the number of parents with exactly two children

Questions 75 76 refer to the following code.


TreeNode w = new TreeNode(90,
new TreeNode( 100,
new TreeNode(45,null,null),
new TreeNode(13,null,null) ),
new TreeNode(200,
new TreeNode(99,null,null),
new TreeNode(13,null,null)));
QUESTION 75xx

What is the output of the following code?


out.println(w.getLeft().getLeft().getValue());
A. 45

B. 200

C. 100

D. 99

E. 13

QUESTION 76 xx

What is the output of the following code?


out.println(w.getLeft().getRight().getValue());
A. 45

B. 200

C. 100

D. 99

E. 13

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 77xx

If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees in
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these

B. 75 150 210 250 225 200


D. 200 150 75 225 210 250

QUESTION 78 xx

If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees pre
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these

B. 75 150 210 250 225 200


D. 200 150 75 225 210 250

QUESTION 79 xx

If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees post
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these

B. 75 150 210 250 225 200


D. 200 150 75 225 210 250

QUESTION 80 xx

If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees reverse
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these

B. 75 150 210 250 225 200


D. 200 150 75 225 210 250

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 81xx

Assuming t does not equal null, which of the following blocks of code would fill // blank 1 so that method fun
would return the minimum value in the tree?
private Comparable fun(TreeNode t)
{
// blank 1
}
I.

II.

while(t!=null)
{
t=t.getLeft();
}
return t.getValue();

A.
B.
C.
D.
E.

while(t!=null&&t.getLeft()!=null)
{
t=t.getLeft();
}
return t.getValue();

III.
while(t!=null)
{
t=t.getLeft();
}
return t;

I
I and II
III only
II and III
II only

QUESTION 82xx

Assuming t does not equal null, which of the following blocks of code would fill // blank 1 so that method fun
would return the maximum value in the tree?
private Comparable fun(TreeNode t)
{
// blank 1
}
I.

II.

while(t!=null)
{
t=t.getRight();
}
return t;

A.
B.
C.
D.
E.

while(t!=null&&t.getRight()!=null)
{
t=t.getRight();
}
return t.getValue();

III.
while(t!=null)
{
t=t.getLeft();
}
return t.getValue();

I
I and II
II only
II and III
III only

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 83xx

What is wrong with the traversal at right?


A. there should be no print
B. the print should be first
C. the print should be in between the recursive calls
D. there is no check for null
E. the method should be public

private void traverse(TreeNode t){


traverse(t.getLeft());
traverse(t.getRight());
out.print(t.getValue() + " ");
}

QUESTION 84xx

How many leaves max could a full tree with 4 levels have?
A. 3
B. 4
C. 5
D. 6
E. 8

QUESTION 85xx

Assuming tree does not equal null, which of the following blocks of code would fill //blank 1 so that method go
would return a String containing all nodes in pre order?
private String go(TreeNode tree)
{
//blank 1
}
I.

if(tree==null)
return"";
return""+go(tree.getLeft())+""+tree.getValue()+""+go(tree.getRight());

II. if(tree==null)

return"";
return""+go(tree.getLeft())+go(tree.getRight())+tree.getValue()+"";

III. if(tree==null)

A.
B.
C.
D.
E.

return"";
return""+tree.getValue()+""+go(tree.getLeft())+go(tree.getRight());

I
I and II
II only
II and III
III only

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 86 xx

Which of the following statements could fill


Matrix constructor would be complete?
A.
B.
C.
D.
E.

<*1>

so the default

mat = new int[10][10];


mat = new int[1][1];
mat = new int[3][3];
mat = new int[0];
more than one of these

public Matrix() {
<*1>

}
public Matrix(int rows, int cols){
<*2>

QUESTION 87 xx

Which of the following statements could fill <*2> so the Matrix


initialization constructor would be complete?
A.
B.
C.
D.
E.

mat = new int[rows][cols];


mat = new int[rows];
mat = new int[r][c];
A and B
A, B, and C

public void setRowSize(int r, int size)


{
mat[r]=new int[size];
}
public void setRow(int r, int[] one)
{
<*3>

for(int i=0; i<one.length; i++)


mat[r][i]=one[i];
}

QUESTION 88 xx

Which of the following statements must fill <*3> so that the size of
one and the size of the receiving row of mat will be the same?
A.
B.
C.
D.
E.

class Matrix
{
private int[][] mat;

setRowSize(r,one.size());
setRowSize(r,one.length);
setRowSize(one.size(),r);
setRowSize(r,one.length());
setRowSize(one.length,r);

public String toString()


{
String output = "";
for(int r=0; <*4> ; r++){
for(int c=0; c<mat[r].length; c++)
output+=mat[r][c];
output+="\n";
}
return output;
}

QUESTION 89 xx

Which of the following statements could fill


would correctly acess all rows in mat?
A.
B.
C.
D.
E.

<*4>

so that the r loop

//test code in the main of another class


Matrix demo = new Matrix(4,6);
//line 1

r<mat[c].length
r<mat.length
r<mat.length()
r<mat.size()
r<mat[r].length

QUESTION 90 xx

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

After executing line 1, how many rows does instance variable mat
contain?
A. 3
B. 4
C. 5
D. 6
E. None of these

QUESTION 91 xx

What is output by line 1?


A.

3.0

B.

5.0

C.

7.0

D.

9.0

E.

1.0

QUESTION 92 xx

What is output by line 2?


A. 5 5

B.

7 7

C. 5 3

D.

5 7

E. 7 5
QUESTION 93 xx

What is output by line 3?


A. 5 5 9

B.

7 7 9

C. 5 5 3

D.

9 5 9

E. 7 5 9
QUESTION 94 xx

What is output by line 4?


A.

3.0

B.

5.0

C.

7.0

D.

9.0

E.

1.0

class Cat
{
private int x, y;
public Cat() {
x=y=5;
}
public void fun() {
x=7;
}
public double go() {
return x;
}
public void back() {
fun();
}
public String toString() {
return x + " " + y;
}
}
class Lion extends Cat
{
private int x;
public Lion() {
x=9;
}
public void fun() {

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

QUESTION 95 xx

What is output by line 5?


A. 5 5 9

B.

7 7 9

C. 5 5 3

D.

9 5 9

E. 7 5 9

x=3;
}
public double go() {
return x;
}
public void back() {
super.back();
}
public String toString() {
return super.toString() + " " + x;
}

//code in the main of another class


Cat fred = new Cat();
System.out.println(fred.go());//line
fred.back();
System.out.println(fred);
//line
fred = new Lion();
System.out.println(fred);
//line
fred.fun();
System.out.println(fred.go());//line
fred.back();
System.out.println(fred);
//line

QUESTION 96 xx

What is output by line 1?


A. class Beluga 0 0 1

class Whale
{
private int x, y;
public static int c;

B. class Beluga 0 0 2

public Whale() {
c++;
}
public void fun() {
x = 6;
}
public int back() {
return 1;
}
public String toString() {
return x + " " + y + " " + c;
}

C. class Beluga 0 0 3
D. class Beluga 0 0 0
E. class Beluga 0 0 5
QUESTION 97 xx

What is output by line 2?


A. class Beluga 0 0 1
B. class Beluga 0 0 2
C. class Beluga 0 0 3
D. class Beluga 0 0 0
E. class Beluga 0 0 5

}
class Beluga extends Whale
{
public void fun() {

A+ Computer Science Ifs/Strings Test www.apluscompsci.com

1
2
3
4
5

System.out.println(back());
}
public int back() {
return 2;
}
public String toString() {
return "class Beluga " + super.toString();
}

QUESTION 98 xx

What is output by line 3?


A. 6 0 2
B. 6 0 3
C. 0 0 4
}

D. 6 0 4
E. 6 0 6
QUESTION 99 xx

What
1.
D is output by line 4?

26. D

A.

B.

27. D

2. A

3.
E
C. 3
D.
4. A4

28. A

E.

5. A5

30. B

6. D

31. C

7.
A. C
class Beluga 0 0 3

32. E

B. D
class Beluga 0 0 4
8.

33. B

29. E

QUESTION 100 xx

What is output by line 5?

C. class Beluga 0 0 6

9. E

34. A

10.
D
E. class
Beluga 0 0 8

35. C

11. B

36. D

12. E

37. C

13. C

38. C

14. E

39. D

15. D

40. B

16. C

41. C

17. B

42. B

18. C

43. A

19. C

44. A

20. B

45. C

21. C

46. C

22. D

47. D

23. D

48. A

D. class Beluga 0 0 5

24. C
25. C

//code in the main of another class


Whale flipper = new Beluga();
System.out.println(flipper);
//line
flipper = new Whale();
flipper = new Beluga();
System.out.println(flipper);
//line
flipper = new Whale();
flipper.fun();
System.out.println(flipper);
//line
flipper = new Beluga();
flipper.fun();
//line
System.out.println(flipper);
//line

A+ Computer 49.
Science
Ifs/Strings Test www.apluscompsci.com
D
50. B

3
4
5

51. A

76. E

52. C

77. C

53. B

78. D

54. B

79. B

55. B

80. A

56. D

81. E

57. B

82. C

58. E

83. D

59. B

84. E

60. A

85. E

61. D

86. E

62. C

87. A

63. B

88. B

64. A

89. B

65. D

90. B

66. C

91. B

67. B

92. E

68. A

93. A

69. E

94. A

70. D

95. C

71. A

96. A

72. C

97. C

73. B

98. D

74. E

99. B

75. A

100. D

A+ Computer Science Final Exam Test www.apluscompsci.com

Das könnte Ihnen auch gefallen