# Meaning of "multiply" in the following code?

• 04-09-2012, 02:55 AM
Pover9000X
Meaning of "multiply" in the following code?
Can someone explain the programming concept of "multiply"? i.e. What is the term for this concept in programming?

public int multiply( int n )

{

if (n == 0)

return 1;

else if (n % 2 ==1)

return n;

else

return n * multiply( n - 2);

}
• 04-09-2012, 03:17 AM
pbrockway2
Re: Meaning of "multiply" in the following code?
Quote:

Can someone explain the programming concept of "multiply"?? i.e. What is the term for this concept in programming?
I think you mean what is the term for a method which calls itself like that. That is "multiply" occurs twice: as the method's name and as part of the expression that is returned.

This is an AP computer science question that is doing the rounds at the moment. I suggest you consult your notes/textbook etc about the term that is used for a method that calls itself. You can find out what the method returns if multiply(8) or whatever is called by running a small program. If you are unclear about *why* that value is returned you should ask (and say what value you think should be returned, and why).