0

Recursion multiplication in Java

I need help in this question!! Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Ex: 7 * 4 4+4+4+4+4+4+4=28

8th Feb 2022, 9:12 PM
Bobby Dike
Bobby Dike - avatar
2 Réponses
+ 2
int multiply(int x, int y) { if(y == 0) return 0; return x + multiply(x, y-1); }
9th Feb 2022, 11:14 AM
Ashish Anand
Ashish Anand - avatar
+ 1
Ashish Anand thank you so much
9th Feb 2022, 7:44 PM
Bobby Dike
Bobby Dike - avatar