Results 1 to 2 of 2
  1. #1
    Pover9000X is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default 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);

    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: 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?
    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).

Similar Threads

  1. Program skips "If" code and goes straight to "Else"
    By Logik22 in forum New To Java
    Replies: 12
    Last Post: 01-21-2012, 05:40 PM
  2. Meaning of "String..."
    By kracer in forum New To Java
    Replies: 1
    Last Post: 05-29-2010, 12:10 AM
  3. what is the meaning of "@" in java
    By itaipee in forum New To Java
    Replies: 3
    Last Post: 08-03-2009, 11:17 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •