Java OCA OCP Practice Question 377

Question

What will the following method return if called with an argument of 7?

public class Main {
   public int transformNumber (int n){ 
      int radix = 2; 
      int output = 0; 
      output += radix*n; /*from   w w w .  j  a  v a  2  s.c  o  m*/
      radix = output/radix; 
      if (output<14){ 
          return output; 
       } 
      else{ 
          output = output*radix/2; 
          return output; 
       } 
      else  { 
          return output/2; 
       } 
   }
}

Select 1 option

  • A. 7
  • B. 14
  • C. 49
  • D. Compilation fails.


Correct Option is  : D

Note

The if-else-else is invalid. It should be if , else if, else.




PreviousNext

Related