Posted By

Cur3n4 on 10/01/11


Tagged


Versions (?)

Answer question 3


 / Published in: Java
 

The first thing to notice is that this is an extremely convoluted way of multiplying two integers. Assuming the code can be compiled using Java 5 the integers can be multiplied as below. If previous jdks versions are used then autoboxing is not available and we have to convert it into a primitive and back into an Integer, but the code will still be cleaner.

The code will fail if y is a negative value, boundary checks. There are other code style issues in the code: the code is hard to read, the y variable is modified when calling multiply, and the ternary operator doesn't help to make the code clearer.

  1. public static final Integer multiply(Integer x, Integer y) {
  2. return x * y;
  3. }

Report this snippet  

You need to login to post a comment.