Name:     ID: 
 
Email: 

Midterm Review

Multiple Choice
Identify the choice that best completes the statement or answers the question.
 

 1. 

What is output by the code below?

int[] array = {33,14,37,11,27};
out.println(array[array.length]);
a.
14
b.
11
c.
33
d.
There is no output due to a runtime exception.
e.
There is no output due to a syntax error.
 

 2. 

What is output by the code below?

int[] array = {7,8,10,11,4,3};
array[array[0]/2]=15;
array[array[4]+1]=9;
array[array.length/2-1]=5;
array[1]=array[0]+4;
out.println(array[2]);
a.
7
b.
11
c.
5
d.
15
e.
9
 

 3. 

What is output by the code below?

int[] array = {5,10,3,6,9,15};
for(int i=0; i<array.length/2; i=i+2)
{  
   array[i]=array[array.length-i-1];
}
out.println(array[0]);
a.
5
b.
10
c.
9
d.
15
e.
6
 

 4. 

What is output by the code below?

int[] array = {5,10,3,6,9,15};
for(int i=0; i<array.length/2; i=i+2)
{
   array[i]=array[array.length-i-1];
}
out.println(array[4]);
a.
5
b.
10
c.
9
d.
15
e.
6
 

 5. 

What is output by the code below?

int[] array = {33,14,37,11,27};
out.println(array[7/2]);
a.
14
b.
11
c.
33
d.
There is no output due to a runtime exception.
e.
There is no output due to a syntax error.
 

 6. 

What is the output by the code below?

String[] ray = {"abc","ade","123","234","678"};
out.println(ray[1]);
a.
abc
b.
ade
c.
123
d.
234
e.
678
 

 7. 

What is output by the code below?

String[] ray = {"abc","ade","123","234","678"};
out.println(ray[5/2]);
a.
abc
b.
ade
c.
123
d.
234
e.
678
 

 8. 

What is output by the code below?

String[] ray = {"abc","ade","123","234","678"};
out.println(ray[4].substring(1));
a.
bc
b.
de
c.
23
d.
34
e.
78
 

 9. 

What is output by the code below?

int[] nums = new int[10];
for (int i=0; i<nums.length; i++)
{
   nums[i] = i*3;
}
out.println(nums[9]);
a.
18
b.
21
c.
15
d.
24
e.
27
 

 10. 

What is output by the code below?

int[] array = {1,2,3,4,5,6};
int sum = 0;
for(int i = 0; i<=array.length; i++)
   sum = sum + array[i];
out.println(sum);
a.
21
b.
28
c.
27
d.
There is no output due to a runtime error.
e.
There is no output due to a syntax error.
 

 11. 

What is returned by method bot given the call shown below?

//client code
int[] ar =  {1,2,3,4,5,6};
System.out.println( bot(ar) );

//method bot
public static int bot( int[] ray )
{
   int stuff = 0;
   for(int i = 0; i<ray.length; i++)  
      stuff = stuff + ray[i];
   return stuff;
}

a.
21
b.
28
c.
27
d.
There is no output due to a runtime error.
e.
There is no output due to a syntax error.
 

 12. 

What is returned by method bot given the call shown below?

//client code
int[] sRay = {2,12,11,45,22,36,5,3,1};
System.out.println( bot(sRay) );

//method bot
public static int bot( int[] ray )
{
   int stuff = 0;
   for(int i = 0; i<ray.length; i++)  
      if(ray[i] % 2 == 0)     
         stuff = stuff + ray[i];
   return stuff;
}

a.
68
b.
72
c.
721674
d.
62
e.
80
 

 13. 

Consider the following instance variable and incomplete method. 
The method getBiggest should return the largest value in tRay.

private int[] tRay;    //assume the tRay contains values

public int getBiggest()
{
  int big = Integer.MIN_VALUE;

      /* code */

  return big;
}

Which of the following code segments shown below could be used to replace
/* code */    
so that getBiggest will work as intended?

I.    for( int i=0; i<tRay.length; i++ )
     if( tRay[i] > big )
        big = tRay[i];


II.   for( int item : tRay )
      if( tRay[item] > big )
         big = tRay[item];


III.  for( int item : tRay )
      if( item > big )
         big = item;


a.
I only
b.
II only
c.
II and III only
d.
I and II only
e.
I and III only
 

 14. 

Consider the following instance variable and incomplete method.  The method sum should
sum up all of the values in array.

private double[] array;    //assume the array contains values

public double sum()
{
  double sum = 0;


  /* code */

  return sum;
}

Which of the following code segments shown below could be used to replace /* code */ so
that sum will work as intended?

I.     for( int i=0; i<array.length; i++)
          sum = sum + array[i];


II.   for( int i=array.length-1; i>-1; i--)
          sum = sum + array[i];


III.  for( int i=0; i<array.length; i++)
          sum = sum + i;

a.
I only
b.
II only
c.
III only
d.
I and II only
e.
I and III only
 

 15. 

Which of the following correctly fill      /* code */   in method    cntOdds() ?
          
//method cntOdds should return the count of all odd numbers in array
public static int cntOdds(int[] array)
{
   int z=0;
   for(int value : array )
   {
     
/*   code   */
         z++;
   }
   return z;
}


a.
if( z % 2 != 0)
b.
if( value % 2 != 0)
c.
if( array[value] % 2 != 0)
d.
if( value % 2 == 0)
e.
if( array[value] % 2 == 0)
 

 16. 

Which of the following correctly fill     /* code */  in method    copyVals() ?
//method copyVals should return a new array
//that contains the first count values from array to num
public static int[] copyVals(int[] array, int count)
{
  
/*   code   */
}

 
a.
int[] nums = new int[count];
for(int i=0; i<count; i++)
{
   nums[i] = array[i];
}
return nums;
b.
int[] nums = new int[count];
for(int i=0, j=0; i<count; i++)
{
   nums[j] = array[i];
}
return nums;
c.
int[] nums = new int[count];
int j = 0;
for(int val : array)
{
   nums[j] = val;
}
return nums;
d.
int[] nums = new int[count];
int j = 0;
for(int val : array)
{
   nums[j] = val;
   j++;
}
return nums;
e.
int[] nums = new int[count];
for(int i=0, j=0; i<count; j++)
{
   nums[j] = array[i];
}
return nums;
 

 17. 

Which of the following correctly fill     /* code */  in method   copy() ?
//method copy method should return a new array that contains
//the first count values from  array excluding occurrences of val
public static int[] copy(int[] ray, int cnt, int val)
{
  
/*   code   */
}

 
a.
int[] nums = new int[cnt];
for(int i=0; i<cnt; i++)
{
   if(ray[i] != val)
      nums[i] = ray[i];
}
return ray;
b.
int[] nums = new int[cnt];
for(int i=0, j=0; j<cnt && i<ray.length; i++)
{
   if(ray[i] != val)
      nums[j++] = ray[i];
}
return nums;
c.
int[] nums = new int[cnt];
int j = 0;
for(int item : array)
{
   if(item != val)
      nums[j++] = item;
}
return nums;
d.
int[] nums = new int[cnt];
int j = 0;
for(int item : array)
{
   nums[j] = item;
   j++;
}
return nums;
e.
int[] nums = new int[count];
for(int i=0, j=0; i<count; i++,j++)
{
   if(array[i] != val)
      nums[j] = array[i];
}
return nums;
 

 18. 

Consider the following instance variable and incomplete method.  The method go should
return the difference between the smallest and largest values in the array.  The array will
contain values that range from Integer.MIN_VALUE to Integer.MAX_VALUE.

private int[] array;    //assume the array contains values

public int go()
{
  int diff = 0;


     /* code */

  return diff;
}

Which of the following code segments shown below could be used to replace /* code */ so
that sum will work as intended?

I.    
int small = 0, big = 0;
for( int i=0; i<array.length; i++)
{
   if( small < array[i] )
     small = array[i];
   if( big > array[i] )
     big = array[i];
}
diff = big - small;


II.  
int small = Integer.MAX_VALUE;
int big = Integer.MIN_VALUE;
for( int i=0; i<array.length; i++)
{
   if( small > array[i] )
     small = array[i];
   if( big < array[i] )
     big = array[i];
}
diff = big - small;


III. 
int small = Integer.MAX_VALUE;
int big = Integer.MIN_VALUE;
for( int i=0; i<array.length; i++)
{
   if( small < array[i] )
     small = array[i];
   if( big > array[i] )
     big = array[i];
}
diff = big - small;

a.
I only
b.
II only
c.
III only
d.
I and II only
e.
I and III only
 

 19. 

Which of the following operators is the logical not operator?
a.
||
b.
&&
c.
!
d.
^
e.
%
 

 20. 

What is output by the code below?

int a=5;
if(a>3 && a<10)
  System.out.print("fun");
System.out.print("go");
a.
go
b.
fun
c.
gofun
d.
fungo
e.
funfun
 

 21. 

What is output by the code below?

int b=5;
if(b>3 && b>10)
  System.out.print("fun");
System.out.print("go");
a.
go
b.
fun
c.
gofun
d.
fungo
e.
funfun
 

 22. 

What is output by the code below?

int d=5;
if(d>3 || d<0)
  System.out.print("fun");
else
  System.out.print("go");
a.
go
b.
fun
c.
gofun
d.
fungo
e.
there is no output
 

 23. 

What is output by the code below?

int e=5;
if(!(e>3))
  System.out.print("fun");
System.out.print("go");
a.
go
b.
fun
c.
gofun
d.
fungo
e.
there is no output
 

 24. 

What is output by the code below?

boolean bFive=true;
boolean bSix=true;
out.println(!(bFive || bSix));
a.
0
b.
1
c.
true
d.
false
e.
bOne
 

 25. 

What is output by the code below?

boolean bSeven=true;
boolean bEight=false;
out.println(bSeven &&(bSeven || bEight));
a.
0
b.
1
c.
true
d.
false
e.
bOne
 

 26. 

Which of the following code segments matches the truth table shown below?

a      b      c
0      0      0
1      1      0
1      0      1
1      1      1
a.
a = b || c
b.
a = b && !c
c.
a = b && c
d.
a = !b && !c
e.
a = !b || !c
 

 27. 

What is output by the code below?

int up=9, in=9;
if(up>4 && ++in>10 || in>9)  
{
   out.print("dude");
}
out.print(in);
a.
dude
b.
dude9
c.
9
d.
10
e.
dude10
 

 28. 

Which of the following expressions is equivalent to the expression shown below?

a && ( b || c )


I.
a && b || a && c

II.
a || b && a || c

III.
a && b || c
a.
I only
b.
II only
c.
III only
d.
I and II only
e.
I and III only
 

 29. 

What is output by the code below?

int pig=1;
do{
   pig=pig+2;
   System.out.print(pig);
}while(pig<5);
a.
35
b.
1234
c.
12345
d.
345
e.
23456
 

 30. 

What is the output by the code below?

int w=1;
do{
   w++;
   System.out.print(w);
}while(w<=5);
a.
234
b.
1234
c.
12345
d.
2345
e.
23456
 

 31. 

What is output by the code below?

int f=4;
int total=0;
do{
   total=total+f;
   f++;
}while(f<9);
out.println(total);
a.
20
b.
18
c.
30
d.
15
e.
24
 

 32. 

What is output by the code below?

int g=13;
int sum=0;
do{
   sum=sum+g;
   g=g-2;;
    }
while(g>0);
out.println(sum);
a.
25
b.
29
c.
49
d.
44
e.
56
 

 33. 

What is output by the code below?

String st = "dog";
for(int a=0; a<st.length(); a++)
{
   for(int b=1;b<=a;b++){
      System.out.print(" ");
   }
   for(int c=a;c<=st.length()/2+1;c++){
      System.out.print(st.charAt(a));
   }
}
a.
dog
b.
god
c.
dddoog
d.
gggood
e.
ddd
 

 34. 

What is output by the code below?

int i = 9;
int j = 10;
do{
   i=i-2;
   j--;
}while(i>5 || j>5);
out.println(i + " - " + j);
a.
3 - 4
b.
-1 - 4
c.
5 - 4
d.
-1 - 5
e.
4 - 5
 

 35. 

Consider the following code segment shown below. 

int x = 5;
while (   /* missing code */   )
{

   System.out.print(x + " ");
   x = x + 5;
}

Listed below are possible replacements for /* missing code */.

I.    x <= 20
II.   x < 20
IIIx <= 19

Which of the proposed replacements for /* missing code */ will cause the code segment to print only the values 5 10 15 20?


a.
I only
b.
I and II only
c.
II only
d.
I and III only
e.
III only
 

 36. 

Consider the following code segment shown below. 

int x = 0;
while (   /* missing code */   )
{

   System.out.print(x + " ");
   x = x + 3;
}

Listed below are possible replacements for /* missing code */.

I.    x <= 12
II.   x < 13
IIIx <= 13

Which of the proposed replacements for /* missing code */ will cause the code segment to print only the values 0 3 6 9 12?


a.
I only
b.
II only
c.
I and II only
d.
II and III only
e.
I, II, and III
 

 37. 

Assume that a game has four doors and the only way to win the game is to successfully find all four doors.  If the player finds all four doors, the method should return true.   If all four doors are not the found, the game should return false.  Each time a door is found, a variable for that door is set to true.

Which of the following code segments could be placed in the method to properly check for the doors and return the appropriate values?

I.  if(doorOne || doorTwo || doorThree || doorFour )
       return true;
     return false;

II. if(doorOne && doorTwo && doorThree && doorFour )
       return true;
     return false;
 
III. if(!doorOne)
       return false;
     if(!doorTwo)
       return false;
     if(!doorThree)
       return false;
     if(!doorFour)
       return false;
     return true;
a.
I only
b.
II only
c.
III only
d.
I and II only
e.
II and III only
 

 38. 

What is output by the code below?

String c = "abc";
if(c.equals("ABC"))  
   out.println("same");
a.
same
b.
abc
c.
ABC
d.
there is no output
e.
789
 

 39. 

What is output by the code below?

int f = 7;
if(f >= 5)  
   out.print("same");
else        
   out.print("notsame");
out.print("done");
a.
same
b.
notsame
c.
done
d.
samedone
e.
notsamedone
 

 40. 

What is output by the code below?

int g = 5;
if(g == 5)
   out.print("same");
else
   out.print("notsame");
out.print("done");
a.
same
b.
notsame
c.
done
d.
samedone
e.
notsamedone
 

 41. 

What is returned by the call go(1)?

public static String go( int k )
{
   if(k >= 2)
      return "1";
   if(k >= 7)
      return "2";
   return "3";
}
a.
1
b.
12
c.
2
d.
13
e.
3
 

 42. 

What returned by the call check("abc","abcd") ?

public static String check(String a, String b)
{
     if(a.compareTo(b) > 0)
        return "bigger";
     if(a.compareTo(b) < 0)
      return "smaller";
   return "equal";
}
a.
0
b.
equal
c.
bigger
d.
smaller
e.
-1
 

 43. 

What returned by the call check("cat","dog") ?

public static String check(String a, String b)
{
     if( a.charAt(0) > b.charAt(0))
        return "bigger";
     if( a.charAt(0) < b.charAt(0) )
      return "smaller";
   return "equal";
}

a.
0
b.
equal
c.
bigger
d.
smaller
e.
-1
 

 44. 

What is output by the code below?

int numA=100, numB=17;
if(numA > 90)
   if(numB > 10)
out.print("go");
out.print("nogo");
a.
go
b.
nogo
c.
gonogo
d.
nogogo
e.
gogo
 

 45. 

What is output by the code below?

int numE=100, numF=10;
if(numE > 90)
   if(numF > 10)
      out.print("go");
   else
out.print("run");
else
   out.print("fly");
out.print("nogo");
a.
go
b.
run
c.
fly
d.
runnogo
e.
nogo
 

 46. 

What is output by the code below?

int numJ = 101;
switch(numJ)
{
   case 11 : out.print("one"); break;
   case 21 : out.print("two"); break;
   case 98 : out.print("three"); break;
   case 101 : out.print("four"); break;
   case 111 : out.print("five"); break;
   case 121 : out.print("six"); break;
}
a.
two
b.
three
c.
four
d.
five
e.
six
 

 47. 

What is output by the code below?

int numK = 101;
switch(numK)
{
   case 11 : out.print("one"); break;
   case 21 : out.print("two");
   case 98 : out.print("three"); break;
   case 101 : out.print("four");
   case 111 : out.print("five"); break;
   case 121 : out.print("six");
}
a.
two
b.
twothree
c.
twothreefour
d.
fourfivesix
e.
fourfive
 

 48. 

What is output by the code below?

int numM = 11;
switch(numM)
{
   case 11 : out.print("one");
   case 21 : out.print("two");
   case 98 : out.print("three"); break;
   case 101 : out.print("four");
   case 111 : out.print("five"); break;
   case 121 : out.print("six");
}
a.
one
b.
onetwo
c.
onetwothree
d.
onetwothreefour
e.
onetwothreefourfive
 

 49. 

What is output by the code below?

int numN = 100, numO = 88;
if(numN > 90)
   if(numO > 90)
      out.print("def")
   else if(numO > 80)
      out.print("xyz");
   else
      out.print("ghi");
out.print("fun");
a.
xyz
b.
xyzdef
c.
xyzfun
d.
deffun
e.
ghifun
 

 50. 

What is output by the code below?

int numP = 100, numQ = 84;
if(numP > 90)
   if(numQ > 90)
      out.print("def");
   else if(numQ > 85)
      out.print("xyz");
   else if(numQ > 80)
      out.print("ghi");
out.print("fun");
a.
ghifun
b.
deffun
c.
def
d.
ghi
e.
fun
 

 51. 

Consider the following instance variables and methods that appear in a class representing robot information.

private int turnsMade;
private double averageSpeed;

public boolean isDizzy()
{
   /* code */
}

A robot is dizzy if at least one of the following conditions is met.

      *    The robot has an average speed less than 25.
      *    The robot has made at least 15 turns.

Consider the following proposed implementations of the   isDizzy   method.

I.
if ( averageSpeed < 25 )
   if ( turnsMade < 15 )
      return true;
return false;


II.
if( averageSpeed < 25 )
   return true;
if( turnsMade > 15 )
   return true;
return false;


III.
if ( averageSpeed < 25 )
   if( turnsMade >= 15 )
      return true;
return false;


Which of the proposed implementations will correclty implement method   isDizzy ?
a.
I only
b.
II only
c.
I and II only
d.
III only
e.
II and III only
 

 52. 

Consider the following instance variables and methods that appear in a class representing robot information.

private int turnsMade;
private double averageSpeed;

public boolean willCrash()
{
   /* code */
}

A robot will crash if at least one of the following conditions is met.

      *    The robot has an average speed greater than 110.
      *    The robot has an average speed greater than 80 and has made at least 7 turns.

Consider the following proposed implementations of the   willCrash   method.

I.
if ( averageSpeed > 110 )
   return true;
return false;


II.
if ( averageSpeed > 110 )
   return true;
if ( averageSpeed > 80 )
  return true;
if ( turnsMade >= 7 )
   return true;
return false;


III.
if ( averageSpeed > 110 )
   return true;
if ( averageSpeed > 80 )
  if( turnsMade >=7 )
     return true;
return false;


Which of the proposed implementations will correclty implement method   willCrash ?
a.
I only
b.
II only
c.
III only
d.
I, II, and III
e.
I and III only
 

 53. 

What relation does   ==  test?
a.
less than
b.
greater than
c.
equal to
d.
less than or equal to
e.
greater than or equal to
 

 54. 

You should never put a ___________what after an open brace?
a.
bracket
b.
car door
c.
window
d.
semicolon
e.
none of these
 

 55. 

What is the output?

int x = 789;
if(x>700)
   out.println("big");
else
   out.println("little");
a.
big
b.
little
c.
700
d.
0
e.
789
 

 56. 

What is the output?

String s = "abc";
if(s.equals("ABC"))
   out.println("same");
a.
same
b.
abc
c.
ABC
d.
789
e.
there is no output
 

 57. 

What is the returned by the call    go(7) ?

public static String go(int x)
{
   if (x==5)
      return "same";
   else if (x>5)
      return "notsame";
   return "done";
}
a.
same
b.
notsame
c.
done
d.
samedone
e.
notsamedone
 

 58. 

What is the returned by the call    go(-6) ?

public static int go(int x)
{
   if( x > 0 )
      return 1;
   return 2;
}
a.
1
b.
12
c.
21
d.
2
e.
0
 

 59. 

What is the returned by the call    go(6) ?

public static int go(int x)
{
   if( x > 0 )
      return 1;
   return 2;
}
a.
1
b.
12
c.
21
d.
2
e.
22
 

 60. 

What is the output?

int a = 4;
if(a>=2)
   out.print("1");
if(a>=7)
   out.print("2");
else
   out.print("3");
a.
123
b.
12
c.
13
d.
3
e.
23
 

 61. 

What is the output?

int a = 9;
if(a>=2)
   out.print("1");
if(a>=7)
   out.print("2");
else
   out.print("3");
a.
123
b.
12
c.
13
d.
3
e.
23
 

 62. 

What is returned by the call   go(2)  ?

public static String go( int a )
{
   if(a>=2)
   {
      if(a>=7)
         return "1";
      return "2";
   }
   return "3";
}
a.
1
b.
2
c.
3
d.
13
e.
12
 

 63. 

What is returned by the call   go(-3)  ?

public static String go( int a )
{
   if(a>=2)
   {
      if(a>=7)
         return "1";
      return "2";
   }
   return "3";
}
a.
1
b.
2
c.
3
d.
12
e.
23
 

 64. 

What is returned by the call   go(4) ?

public static int go( int a )
{
   int ans = 0;
   if(a>=2)
   {
      if(a>=7)
         ans += 1;
      ans += 2;
   }
   ans += 3;
   return ans;
}

a.
1
b.
2
c.
3
d.
5
e.
6
 

 65. 

What is returned by the call   go(100,88)?

public static String go(int x, int z)
{
  String s = "";
  if(x > 90)   
    if(z > 95)     
       s += "def";  
    else     
       s += "xyz";
  else  
    s += "ghi";
  s += "fun";
  return s;
}
a.
xyz
b.
xyzghi
c.
xyzfun
d.
deffun
e.
ghifun
 

 66. 

What is returned by the call   go(80,88)?

public static String go(int x, int z)
{
  String s = "";
  if(x>90)   
    if(z>95)     
       s += "def";  
    else     
       s += "xyz";
  else  
    s += "ghi";
  s += "fun";
  return s;
}
a.
ghifun
b.
deffun
c.
def
d.
ghi
e.
fun
 

 67. 

What is returned by the call   go(93,95)?

public static String go(int x, int z)
{
  String s = "";
  if(x>90)   
    if(z>95)     
       s += "def";  
    else     
       s += "xyz";
  else  
    s += "ghi";
  s += "fun";
  return s;
}
a.
ghifun
b.
deffun
c.
def
d.
ghifun
e.
xyzfun
 

 68. 

What is returned by the call  go("actors")?

public static String go( String s )
{
   if(s.length()>5)
      return s.substring(2,4);
   if(s.length()>1)
      return "" + s.charAt(1) + s.charAt(s.length()-1);
   return s;
}
a.
tor
b.
act
c.
tors
d.
to
e.
cs
 

 69. 

What is the output of the call  go("grid")?

public static String go( String s )
{
   if(s.length()>5)
      return s.substring(2,4);
   if(s.length()>1)
      return "" + s.charAt(1) + s.charAt(s.length()-1);
   return s;
}

a.
grid
b.
id
c.
rd
d.
rid
e.
grd
 

 70. 

What is returned by the call  go("alley","cricket")?

public static String go( String one, String two)
{
   if(one.length()>two.length())
      return "bigger";
   if(one.length()<two.length())
      return "smaller";
   return "equal";
}
a.
0
b.
equal
c.
bigger
d.
smaller
e.
-1
 

 71. 

What is returned by the call  go("alligator","cricket") ?

public static String go( String one, String two)
{
   if(one.length()>two.length())
      return "bigger";
   if(one.length()<two.length())
      return "smaller";
   return "equal";
}

a.
0
b.
equal
c.
bigger
d.
smaller
e.
-1
 

 72. 

What is returned by the call  go("comps") ?

public static String go( String s )
{
   if(s.length()%2==0)
     return s.substring(0,s.length()/2);
   return s.substring(0,s.length()/3);
}
a.
c
b.
co
c.
com
d.
comp
e.
comps
 

 73. 

What is returned by the call  go("boat")?

public static String go( String s )
{
   if(s.length()%2==0)
     return s.substring(0,s.length()/2);
   return s.substring(0,s.length()/3);
}
a.
bo
b.
boat
c.
boa
d.
bat
e.
at
 

 74. 

What is returned by the call go("zebra")?

public static String go( String s )
{
   if(s.indexOf("x")>-1)
     return "one";
   if(s.indexOf("y")>-1)
     return "two";
   if(s.indexOf("z")>-1)
     return "three";
   return "no";
}
a.
one
b.
two
c.
three
d.
no
e.
-1
 

 75. 

What is returned by the call  go("funny")?

public static String go( String s )
{
   if(s.indexOf("x")>-1)
     return "one";
   if(s.indexOf("y")>-1)
     return "two";
   if(s.indexOf("z")>-1)
     return "three";
   return "no";
}
a.
one
b.
two
c.
three
d.
no
e.
-1
 

 76. 

Consider the incomplete method implementation below.  Which of the following could correctly fill    /* code */   so that the method would return true if both String parameters contain the same letters in the same order in the same case?

public boolean areTheyTheSame( String s, String t )
{
    /* code */ 
}

I.
if(!s.equals(t))
  return false;
return true;

II.
if(s!=t)
  return false;
return true;

III.
if(!s.compareTo(t)==0)
  return false;
return true;
a.
I only
b.
II only
c.
III only
d.
I and II only
e.
I and III only
 

 77. 

What is the output?

System.out.print(3 + 3 * 3);
a.
27
b.
9
c.
12
d.
6
e.
15
 

 78. 

What is output by the code below?

System.out.println( Math.ceil(6.7) );
a.
6.0
b.
7.0
c.
8.0
d.
9.0
e.
27.0
 

 79. 

What is output by the code below?

System.out.println( Math.pow(3,3) );
a.
6.0
b.
7.0
c.
8.0
d.
9.0
e.
27.0
 

 80. 

What is output by the code shown below?

double x = 9.0;
x = x + 2;
System.out.print(x);
a.
11
b.
11.2
c.
11.0
d.
0
e.
27.0
 

 81. 

What is output by the code below?

int x = 9,
y = 8;
int z = x + y;
double a = z;
System.out.print(a);
a.
8
b.
9
c.
17
d.
17.0
e.
27.0
 

 82. 

How many methods are there in class It?

public class It
{  
   private int myX;  
  
   public It()
   {
      myX = 99;
   }

   public int getX()
   {
      return myX;
   }

   public String toString()
   {       
      return "" + getX();  
   }
}
a.
0
b.
1
c.
2
d.
3
e.
4
 

 83. 

How many accessor methods are there in class It?

public class It
{  
   private int myX;  
  
   public It()
   {
      myX = 99;
   }

   public int getX()
   {
      return myX;
   }

   public String toString()
   {       
      return "" + getX();  
   }
}
a.
0
b.
1
c.
2
d.
3
e.
4
 

 84. 

What is output by the code below?

public class Check     
{  
   private int fun;  

   public void change() 
   {     
      fun = 100;
      int fun = 99;     
   }

   public String toString()
   {
      return " " + fun;  
   }
}

//client code
Check test = new Check();     
test.change();
out.println(test); 
a.
0
b.
100
c.
99
d.
101
e.
There is no output due to a syntax error.
 

 85. 

What is output by the code below?

public class Check
{  
   private int one, two, total;        

   public void setNums(int n1, int n2)
   {
      one = n1;
      two = n2;
   }

   public void add()
   {
      total = one + two;
   }

   public String toString()
   {
      return "" + total;
   }
}

//code in the main of another class
Check test = new Check();
test.setNums(9,7);
test.add();
out.println(test);
a.
0
b.
12
c.
14
d.
16
e.
2
 

 86. 

What is output by the code below?

public class Check
{  
   private int one, two, total;        

   public void setNums(int n1, int n2)
   {
      one = n1;
      two = n2;
   }

   public void add()
   {
      total = one + two;
      two = 9;
   }

   public String toString()
   {
      total = 2;
      return "" + total;
   }
}

//code in the main of another class
Check test = new Check();
test.setNums(9,7);
test.add();
out.println(test);
a.
18
b.
12
c.
14
d.
16
e.
2
 

 87. 

What is output by the code below?

public class Check
{  
   private int one, two, total;        

   public void setNums(int n1, int n2)
   {
      one = n1;
      two = n2;
   }

   public void add()
   {
      one = 5;
      total = one + two;
      two = 5;
   }

   public String toString()
   {
      return "" + total;
   }
}

//code in the main of another class
Check test = new Check();
test.setNums(9,7);
test.add();
out.println(test);
a.
10
b.
12
c.
14
d.
16
e.
2
 

 88. 

What is the output by the code below? 

System.out.print("abc" );
a.
abc
b.
a
c.
c
d.
c
e.
cba
 

 89. 

What is the output by the code below? 

System.out.print("a\tc" );
a.
a\tc
b.
a     c
c.
atc
d.
a\c
e.
ac
 

 90. 

In Java, every program statement ends with a what ?
a.
{
b.
}
c.
;
d.
\
e.
(
 

 91. 

Which of the following lines correctly defines a String variable?
a.
String s = cdef;
b.
s = "cdef";
c.
String s = "cdef";
d.
String = "cdef";
e.
String;
 

 92. 

Which of the following lines correctly defines an integer variable?
a.
int i = 234
b.
i = 234;
c.
integer = 234;
d.
int i = 234;
e.
integer i = 23;
 

 93. 

Which of the following methods would move the cursor down to the next line?
a.
print()
b.
println()
c.
printLn()
d.
printLINE()
e.
prinT()
 

 94. 

Every method must have an open and close what?
a.
period
b.
bracket
c.
semicolon
d.
brace
e.
chickens
 

 95. 

Which of the following is the tab character?
a.
\t
b.
\r
c.
\n
d.
\nl
e.
\b
 

 96. 

Which of the following would print one backslash on the screen if used in a print( ) or  println( )?
a.
\\
b.
\
c.
/\
d.
\\\
e.
\b
 

 97. 

What is the output by the code below?

int x = 9;
double y = x;
System.out.println(y);
a.
9
b.
9.0
c.
0
d.
There is no output due to a syntax error.
e.
There is no output due to a runtime error.
 

 98. 

What is the output by the code below?

double y = 9.0;
int x = y;
System.out.println(x);
a.
9
b.
9.0
c.
0
d.
There is no ouptut due to a syntax error.
e.
There is no ouptut due to a runtime error.
 

 99. 

What is the ASCII value of ‘b’?
a.
43
b.
98
c.
48
d.
66
e.
97
 

 100. 

What is the ASCII value of ‘B’?
a.
44
b.
97
c.
66
d.
43
e.
65
 



 
         Start Over