Answer question 3


/ Published in: Java
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. public static final Integer multiply(Integer x, Integer y) {
  2. return x * y;
  3. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.