Hey.. Am taking the practice AP Computer Science A tests to prep for the AP exam..Would appreciate it if you guys could verify if my answers are correct..:
1) When will method whatIsIt cause a stack overflow (i.e., cause computer memory to be exhausted )
A) Only when X<y
B) Only when X<=y
C) Only when X>y
D) For all values of x and y
E) The method will never cause a stock overflow
I chose E .since dont se any reason why it should overflow.......
________________________________________________________________________
2) The boolean expression a==max || !(max !=a) can be simplified to
A) a==max
B) a!=max
C) a<max || a>max
D) True
E) False
I choose A
________________________________________________________________________
3) Suppose an ArrayList list is initialized with integer values. Which of the following will not cause an IndexOutOfBoundsException to be thrown?
A) for ( int i=0;i<=list.size();i++)
list.set(i,new Integer(0));
B) list.add(list.size(),new Integer(0));
C) Integer int0b=list.get(list.size());
D) Integer int0b=list.remove(list.size());
E) list.add(-1,new Integer(0));
have no idea in this case. E and B dont seem right because the keyword New would result in a compile time error. A cant be right either. so am left with C and D
_______________________________________________________________________
4)
//<postcondition>
public static void doSomething(ArrayList a, int i, int j)
{
Object temp=a.get(i);
a.set(i,a.get(j));
a.set(j,temp);
}
Which best describes the postcondition for doSomething?
A) removes from a the objects indexed at i and j
B) resplaces in a the object indexed at i with the object indexed at j.
C) replaces in a the object indexed at j with the object indexed at i
D) replaces in a the objects indexed at i and j with temp.
E) interchanges in a the objects indexed at i and j
I choose E
________________________________________________________________________
5) What will be output as a result of the method call whatsIt(347)?
A) 74
B) 47
C) 734
D) 743
E)347
I choose A
_________________________________________________________________________
6) A large list of numbers is to be sorted in ascending order. Which of the following is a true statement?
A) if the array is initially sorted in descending order, then insertion sort will be more efficient than selection sort.
B) the number of comparisons for selection sort is independent of the initial arrangement of elements.
C) the number of comparisons for insertion sort is independent of hte initial arrangements of elements.
D) the number of data movements in selection sort depends on the initial arragenment of elements.
E) The number of data movements in insertino sort is indepent of the initial arrangement of elements.
I choose D but not sure.
________________________________________________________________________
7) Which of the following will execute without throwing an exceptoin?
A) String s=null;
String t="";
if (s.equals(t))
System.out.println("holy moly!");
B) String s="holy";
String t="moly";
if (s.equals(t))
System.out.println("holy moly!");
C) String s="holy";
String t=s.substring(4);
System.out.println(s+t);
A) A only
B) B only
C) C only
D) A and B only
E) B and C only
I choose E
______________________________________________________________________
8) Consider the array a with values as shown:
4,7,19,25,36,37,50,100,101,205,220,271,306,321
where 4 is a [0] and 321 is a [13]. Suppose that the search method is called with first=0 and last =13 to locate the key 205. HOw many iterations of the while loop must be made in order to locate it?
A) 3
B) 4
C)5
D) 10
E)13
Totally clueless on this one!
I'd really appreciate help with these. Thanks
1) When will method whatIsIt cause a stack overflow (i.e., cause computer memory to be exhausted )
Code:
public static int whatIsIt(int x,int y)
{
if (x>y)
return x*y;
else
return whatIsIt(x-1,y);
}
A) Only when X<y
B) Only when X<=y
C) Only when X>y
D) For all values of x and y
E) The method will never cause a stock overflow
I chose E .since dont se any reason why it should overflow.......
________________________________________________________________________
2) The boolean expression a==max || !(max !=a) can be simplified to
A) a==max
B) a!=max
C) a<max || a>max
D) True
E) False
I choose A
________________________________________________________________________
3) Suppose an ArrayList list is initialized with integer values. Which of the following will not cause an IndexOutOfBoundsException to be thrown?
A) for ( int i=0;i<=list.size();i++)
list.set(i,new Integer(0));
B) list.add(list.size(),new Integer(0));
C) Integer int0b=list.get(list.size());
D) Integer int0b=list.remove(list.size());
E) list.add(-1,new Integer(0));
have no idea in this case. E and B dont seem right because the keyword New would result in a compile time error. A cant be right either. so am left with C and D
_______________________________________________________________________
4)
//<postcondition>
public static void doSomething(ArrayList a, int i, int j)
{
Object temp=a.get(i);
a.set(i,a.get(j));
a.set(j,temp);
}
Which best describes the postcondition for doSomething?
A) removes from a the objects indexed at i and j
B) resplaces in a the object indexed at i with the object indexed at j.
C) replaces in a the object indexed at j with the object indexed at i
D) replaces in a the objects indexed at i and j with temp.
E) interchanges in a the objects indexed at i and j
I choose E
________________________________________________________________________
5) What will be output as a result of the method call whatsIt(347)?
A) 74
B) 47
C) 734
D) 743
E)347
I choose A
_________________________________________________________________________
6) A large list of numbers is to be sorted in ascending order. Which of the following is a true statement?
A) if the array is initially sorted in descending order, then insertion sort will be more efficient than selection sort.
B) the number of comparisons for selection sort is independent of the initial arrangement of elements.
C) the number of comparisons for insertion sort is independent of hte initial arrangements of elements.
D) the number of data movements in selection sort depends on the initial arragenment of elements.
E) The number of data movements in insertino sort is indepent of the initial arrangement of elements.
I choose D but not sure.
________________________________________________________________________
7) Which of the following will execute without throwing an exceptoin?
A) String s=null;
String t="";
if (s.equals(t))
System.out.println("holy moly!");
B) String s="holy";
String t="moly";
if (s.equals(t))
System.out.println("holy moly!");
C) String s="holy";
String t=s.substring(4);
System.out.println(s+t);
A) A only
B) B only
C) C only
D) A and B only
E) B and C only
I choose E
______________________________________________________________________
8) Consider the array a with values as shown:
4,7,19,25,36,37,50,100,101,205,220,271,306,321
where 4 is a [0] and 321 is a [13]. Suppose that the search method is called with first=0 and last =13 to locate the key 205. HOw many iterations of the while loop must be made in order to locate it?
A) 3
B) 4
C)5
D) 10
E)13
Totally clueless on this one!
I'd really appreciate help with these. Thanks
