Recursion: Multiplication by Addition

Published by Deep Xavier in

Create a function that returns the product of two integers. This process of multiplication can be achieved via repetitive addition, thus, the process can be done recursively.

Examples

multiply(10, 2) ➞ 20

multiply(-51, -4) ➞ 204

multiply(3, 9) ➞ 27

multiply(-21, 5) ➞ -105

multiply(1024, 7) ➞ 7168

multiply(273, -6) ➞ -1638

Notes

  • You are expected to solve this challenge via recursion.
  • You can check on the Resources tab for more details about recursion in Java.
  • If you think recursion is fun, a collection of those challenges can be found here.
Watch a quick demo on how Edabit works.