Solution..
package com.shashikumar.com;
public class multiplication {
public static void main(String []args)
{
multiplication t=new multiplication();
int a=10,b=88;//should give 880 when we multiply.
System.out.print(t.multiply(a,b));
}
public int multiply(int x,int y)
{
if(y==1)
return x;
else
return (sumNumbers(x,y));
}
public int sumNumbers(int m,int n)
{
if(n==1)
return m;
else
return m+sumNumbers(m,n-1);
}
}
output:
---------------------------
880
package com.shashikumar.com;
public class multiplication {
public static void main(String []args)
{
multiplication t=new multiplication();
int a=10,b=88;//should give 880 when we multiply.
System.out.print(t.multiply(a,b));
}
public int multiply(int x,int y)
{
if(y==1)
return x;
else
return (sumNumbers(x,y));
}
public int sumNumbers(int m,int n)
{
if(n==1)
return m;
else
return m+sumNumbers(m,n-1);
}
}
output:
---------------------------
880
Không có nhận xét nào:
Đăng nhận xét