Semester Final CS3
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
30 Questions
1 point
1
Question 1
1.
What is output by the code below?String[] ray;ray = new String[4];System.out.println( ray[0] );
What is output by the code below?
String[] ray;
ray = new String[4];
System.out.println( ray[0] );
1 point
1
Question 2
2.
What is output by the code below?Integer[] ray;ray = new Integer[4];System.out.println( ray[3] );
What is output by the code below?
Integer[] ray;
ray = new Integer[4];
System.out.println( ray[3] );
1 point
1
Question 3
3.
What is output by the code below?Integer[] ray;ray = new Integer[4];ray[1] = null;ray[0] = new Integer(3);ray[2] = new Integer(99);System.out.println( ray[2] );
What is output by the code below?
Integer[] ray;
ray = new Integer[4];
ray[1] = null;
ray[0] = new Integer(3);
ray[2] = new Integer(99);
System.out.println( ray[2] );
1 point
1
Question 4
4.
What is output by the code below?Integer[] ray = {11,55,-4,909};System.out.println( ray[3] );
What is output by the code below?
Integer[] ray = {11,55,-4,909};
System.out.println( ray[3] );
1 point
1
Question 5
5.
What is output by the code below?Double[] ray = {11.2,55.0,-4.5,909.0};System.out.println( ray[1] );
What is output by the code below?
Double[] ray = {11.2,55.0,-4.5,909.0};
System.out.println( ray[1] );
1 point
1
Question 6
6.
What is output by the code below?Double[] ray = {11.2,7.2,-4.5,909.0};ray[1] = new Double(55.0);System.out.println( ray[1] );
What is output by the code below?
Double[] ray = {11.2,7.2,-4.5,909.0};
ray[1] = new Double(55.0);
System.out.println( ray[1] );
1 point
1
Question 7
7.
What is output by the code below?Double[] ray = {3.2,5.7,6.3,1.9};double x = 0;for( double r : ray ) x += r;System.out.println( x );
What is output by the code below?
Double[] ray = {3.2,5.7,6.3,1.9};
double x = 0;
for( double r : ray )
x += r;
System.out.println( x );
1 point
1
Question 8
8.
What is output by the code below?Double[] ray = {3.1,5.2,6.3,1.4};for( double r : ray ) r = 0;System.out.println( ray[2] );
What is output by the code below?
Double[] ray = {3.1,5.2,6.3,1.4};
for( double r : ray )
r = 0;
System.out.println( ray[2] );
1 point
1
Question 9
9.
What is output by the code below?String[] ray;ray = new String[4];ray[1] = "one";System.out.println( ray[1] );
What is output by the code below?
String[] ray;
ray = new String[4];
ray[1] = "one";
System.out.println( ray[1] );
1 point
1
Question 10
10.
What is output by the code below?String[] ray;ray = new String[4];ray[1] = "one";ray[2] = "two";ray[3] = "three";System.out.println( ray[0] );
What is output by the code below?
String[] ray;
ray = new String[4];
ray[1] = "one";
ray[2] = "two";
ray[3] = "three";
System.out.println( ray[0] );
1 point
1
Question 11
11.
What do you call the condition that stops recursion?
What do you call the condition that stops recursion?
1 point
1
Question 12
12.
What is returned the call fun(6) ?public static int fun(int x){ if(x < 1) return 1; else return x + fun(x - 1);}
What is returned the call fun(6) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
1 point
1
Question 13
13.
What is returned by the call fun(8) ?public static int fun(int x){ if(x < 1) return 1; else return x + fun(x - 1);}
What is returned by the call fun(8) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x + fun(x - 1);
}
1 point
1
Question 14
14.
What is returned by the call fun(8) ?public static int fun(int x){ if(x < 1) return 1; else return x + fun(x - 2);}
What is returned by the call fun(8) ?
public static int fun(int x){
if(x < 1)
return 1;
else
return x + fun(x - 2);
}
1 point
1
Question 15
15.
What is returned by the call fun(6) ?public static int fun(int x){ if(x < 1) return 1; else return x + fun(x - 2);}
What is returned by the call fun(6) ?
public static int fun(int x){
if(x < 1)
return 1;
else
return x + fun(x - 2);
}
1 point
1
Question 16
16.
What is returned by the call wacky(4,6) ?public static int wacky(int x, int y){ if(x <= 1) return y; else return wacky(x - 1,y - 1) + y;}
What is returned by the call wacky(4,6) ?
public static int wacky(int x, int y){
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
1 point
1
Question 17
17.
Which of the following sorts splits data into smaller lists, sorts the smaller lists, and then combines all of the sorted smaller lists back into one big list?
Which of the following sorts splits data into smaller lists, sorts the smaller lists, and then combines all of the sorted smaller lists back into one big list?
1 point
1
Question 18
18.
What is output by the code below?ArrayList<Integer> r;r = new ArrayList<Integer>();r.add(1);r.add(2);r.add(3);out.println( r.indexOf(100) );
What is output by the code below?
ArrayList<Integer> r;
r = new ArrayList<Integer>();
r.add(1);
r.add(2);
r.add(3);
out.println( r.indexOf(100) );
1 point
1
Question 19
19.
What type of sort is funSort()?public static void funSort( int[] ray ){ for(int i=0; i< ray.length-1; i++) { int max = i; for(int j = i+1; j<ray.length; j++) { if( ray[j] > ray[max] ) max = j; } if( max != i){ int temp = ray[max]; ray[max] = ray[i]; ray[i] = temp; } }}
What type of sort is funSort()?
public static void funSort( int[] ray )
{
for(int i=0; i< ray.length-1; i++)
{
int max = i;
for(int j = i+1; j<ray.length; j++)
{
if( ray[j] > ray[max] )
max = j;
}
if( max != i){
int temp = ray[max];
ray[max] = ray[i];
ray[i] = temp;
}
}
}
1 point
1
Question 20
20.
For the code at right to correctly implement a linear search, which of the following would correctly fill < blank 1 > ?public static int find( ArrayList list, Object param ){ for(int i=0; i < list.size(); i++) { if( list.get(i).equals(param) ) return i; } < blank 1 >}
For the code at right to correctly implement a linear search, which of the following would correctly fill < blank 1 > ?
public static int find( ArrayList list, Object param )
{
for(int i=0; i < list.size(); i++)
{
if( list.get(i).equals(param) )
return i;
}
< blank 1 >
}
1 point
1
Question 21
21.
How many times would help() be called before list was sorted?public void sort( int[] list, int front, int back){ int mid = (front+back)/2; if( mid==front) return; sort(list, front, mid); sort(list, mid, back); help(list, front, back);}private void help(int[] list, int front, int back){ int[] temp = new int[back-front]; int i = front, j = (front+back)/2, k =0; int mid =j; while( i<mid && j<back) { if(list[i]< list [j]) temp[k++]= list[i++]; else temp[k++]= list[j++]; } while(i<mid) temp[k++]= list[i++]; while(j<back) temp[k++]= list[j++]; for(i = 0; i<back-front; ++i) list[front+i]=temp[i];}//code in the mainint[] list = {39,6,11,23,18,3,20,5,57};sort(list, 0, list.length);
How many times would help() be called before list was sorted?
public void sort( int[] list, int front, int back)
{
int mid = (front+back)/2;
if( mid==front) return;
sort(list, front, mid);
sort(list, mid, back);
help(list, front, back);
}
private void help(int[] list, int front, int back)
{
int[] temp = new int[back-front];
int i = front, j = (front+back)/2, k =0;
int mid =j;
while( i<mid && j<back)
{
if(list[i]< list [j])
temp[k++]= list[i++];
else
temp[k++]= list[j++];
}
while(i<mid)
temp[k++]= list[i++];
while(j<back)
temp[k++]= list[j++];
for(i = 0; i<back-front; ++i)
list[front+i]=temp[i];
}
//code in the main
int[] list = {39,6,11,23,18,3,20,5,57};
sort(list, 0, list.length);
1 point
1
Question 22
22.
If ray is storing 10 elements, what is the maximum number of swaps funSort() could make in order to put the elements in order?public static void funSort( int[] ray ){ for(int i=0; i< ray.length-1; i++) { int max = i; for(int j = i+1; j < ray.length; j++) { if( ray[j] > ray[max] ) max = j; } if( max != i){ int temp = ray[max]; ray[max] = ray[i]; ray[i] = temp; } }}
If ray is storing 10 elements, what is the maximum number of swaps funSort() could make in order to put the elements in order?
public static void funSort( int[] ray )
{
for(int i=0; i< ray.length-1; i++)
{
int max = i;
for(int j = i+1; j < ray.length; j++)
{
if( ray[j] > ray[max] )
max = j;
}
if( max != i){
int temp = ray[max];
ray[max] = ray[i];
ray[i] = temp;
}
}
}
1 point
1
Question 23
23.
If funSearch() will only work on sorted data, what type of sort is funSearch()?public static int funSearch( int[] list, int val ){ int len=list.length; int bot=0, top=len-1; int middle=0; while( bot <= top ) { middle=(bot+top)/2; if (list[middle] == val) return middle; else if(list[middle]>val) top=middle-1; else bot=middle+1; } return -1;}
If funSearch() will only work on sorted data, what type of sort is funSearch()?
public static int funSearch( int[] list, int val )
{
int len=list.length;
int bot=0, top=len-1;
int middle=0;
while( bot <= top )
{
middle=(bot+top)/2;
if (list[middle] == val)
return middle;
else
if(list[middle]>val)
top=middle-1;
else
bot=middle+1;
}
return -1;
}
1 point
1
Question 24
24.
funSort() will put the items in ray in what type of order?public static void funSort( int[] ray ){ for(int i=0; i< ray.length-1; i++) { int max = i; for(int j = i+1; j < ray.length; j++) { if( ray[j] > ray[max] ) max = j; } if( max != i){ int temp = ray[max]; ray[max] = ray[i]; ray[i] = temp; } }}
funSort() will put the items in ray in what type of order?
public static void funSort( int[] ray )
{
for(int i=0; i< ray.length-1; i++)
{
int max = i;
for(int j = i+1; j < ray.length; j++)
{
if( ray[j] > ray[max] )
max = j;
}
if( max != i){
int temp = ray[max];
ray[max] = ray[i];
ray[i] = temp;
}
}
}
1 point
1
Question 25
25.
Which sort is shown below?public void sort( int[] list, int front, int back){ int mid = (front+back)/2; if( mid==front) return; sort(list, front, mid); sort(list, mid, back); help(list, front, back);}private void help(int[] list, int front, int back){ int[] temp = new int[back-front]; int i = front, j = (front+back)/2, k =0; int mid =j; while( i<mid && j<back) { if(list[i]< list [j]) temp[k++]= list[i++]; else temp[k++]= list[j++]; } while(i<mid) temp[k++]= list[i++]; while(j<back) temp[k++]= list[j++]; for(i = 0; i<back-front; ++i) list[front+i]=temp[i];}
Which sort is shown below?
public void sort( int[] list, int front, int back)
{
int mid = (front+back)/2;
if( mid==front) return;
sort(list, front, mid);
sort(list, mid, back);
help(list, front, back);
}
private void help(int[] list, int front, int back)
{
int[] temp = new int[back-front];
int i = front, j = (front+back)/2, k =0;
int mid =j;
while( i<mid && j<back)
{
if(list[i]< list [j])
temp[k++]= list[i++];
else
temp[k++]= list[j++];
}
while(i<mid)
temp[k++]= list[i++];
while(j<back)
temp[k++]= list[j++];
for(i = 0; i<back-front; ++i)
list[front+i]=temp[i];
}
1 point
1
Question 26
26.
What would be the value of list after four passes of the help() method?public void sort( int[] list, int front, int back){ int mid = (front+back)/2; if( mid==front) return; sort(list, front, mid); sort(list, mid, back); help(list, front, back);}private void help(int[] list, int front, int back){ int[] temp = new int[back-front]; int i = front, j = (front+back)/2, k =0; int mid =j; while( i<mid && j<back) { if(list[i]< list [j]) temp[k++]= list[i++]; else temp[k++]= list[j++]; } while(i<mid) temp[k++]= list[i++]; while(j<back) temp[k++]= list[j++]; for(i = 0; i<back-front; ++i) list[front+i]=temp[i];}//code in the mainint[] list = {39,6,11,23,18,3,20,5,57};sort(list, 0, list.length);
What would be the value of list after four passes of the help() method?
public void sort( int[] list, int front, int back)
{
int mid = (front+back)/2;
if( mid==front) return;
sort(list, front, mid);
sort(list, mid, back);
help(list, front, back);
}
private void help(int[] list, int front, int back)
{
int[] temp = new int[back-front];
int i = front, j = (front+back)/2, k =0;
int mid =j;
while( i<mid && j<back)
{
if(list[i]< list [j])
temp[k++]= list[i++];
else
temp[k++]= list[j++];
}
while(i<mid)
temp[k++]= list[i++];
while(j<back)
temp[k++]= list[j++];
for(i = 0; i<back-front; ++i)
list[front+i]=temp[i];
}
//code in the main
int[] list = {39,6,11,23,18,3,20,5,57};
sort(list, 0, list.length);
1 point
1
Question 27
27.
What is returned by the call wacky(2,6) ?public static int wacky(int x, int y){ if(x <= 1) return y; else return wacky(x - 1,y - 1) + y;}
What is returned by the call wacky(2,6) ?
public static int wacky(int x, int y)
{
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
1 point
1
Question 28
28.
What is returned by the call fun(1) ?public static int fun(int x){ if(x < 1) return 1; else return x - fun(x - 3);}
What is returned by the call fun(1) ?
public static int fun(int x)
{
if(x < 1)
return 1;
else
return x - fun(x - 3);
}
1 point
1
Question 29
29.
What is returned by the call wacky(5,5) ?public static int wacky(int x, int y){ if(x <= 1) return y; else return wacky(x - 1,y - 1) + y;}
What is returned by the call wacky(5,5) ?
public static int wacky(int x, int y){
if(x <= 1)
return y;
else
return wacky(x - 1,y - 1) + y;
}
1 point
1
Question 30
30.
What is returned by the call fun(10) ?public static int fun(int x){ if (x < 1) return x; else return x + fun(x - 2);}
What is returned by the call fun(10) ?
public static int fun(int x)
{
if (x < 1)
return x;
else
return x + fun(x - 2);
}