CS315: Algorithms and Data Structures <Spring 2008: 55525-45>

Quiz #2 <29 Jan 2008>

Question #1

What is the output of the following method?

 public static void main (String[] args) {
   final int i = -3;
   System.out.print(Integer.toBinaryString(i)+" ");
   System.out.print(Integer.toHexString(i)+" ");
   System.out.println(Integer.toOctalString(i));
   }
 
  1. 11111111111111111111111111111101 37777777775 fffffffd
  2. 10000000000000000000000000000011 20000000003 80000003
  3. 10000000000000000000000000000011 80000003 20000000003
  4. 11111111111111111111111111111101 fffffffd 37777777775
  5. 10000000000000000000000000000011 0x80000003 020000000003

Answer #d

Question #2

What is the output of the following method? 
 public static void main (String[] args) {

 int v1 = 5;  
 int v2 = 2;

 System.out.print(~v1 + " "); 
 System.out.print((v1 & v2) + " ");
 System.out.print((v1 | v2) + " ");
 System.out.print((v1 ^ v2) + " ");
 System.out.print((-v1 >> v2) + " ");
 System.out.print((v1 << v2) + " ");
 System.out.println(Integer.toBinaryString(-v1 >>> v2));
 }
  1. -5 0 7 7 -2 20 111111111111111111111111111110
  2. -5 5 7 7 -1 20 111111111111111111111111111101
  3. -6 0 7 7 -2 20 111111111111111111111111111110
  4. false false true true -2 20 111111111111111111111111111110
  5. -6 0 7 7 -2 20 111111111111111111111111111101

Answer #c

Question #3

Which of these is not a javadoc tag?
  1. @param
  2. @error
  3. @throws
  4. @return
  5. @author

Answer #b