I thought this would be relatively easy but running it, gives wrong result. It may be the initialization of the result variable but I cant seem to be able to modify the code such as to be correct. Here is my progress so far.
public class test
{
public static void main(String[] args)
{
int num1 = 10;
int num2 = 4;
int res = product(num1, num2);
System.out.println(res);
}
public static int product(int n1, int n2)
{
int result = 0 ;
if (n2 > 0)
{
result = result + n1 ;
product(n1,n2-1) ;
}
return result ;
}
}
better solution
*here*