Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: AP computer science questions

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    My Mood
    Cheerful
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default AP computer science questions

    public int multiply( int n )

    {

    if (n == 0)

    return 1;

    else if (n % 2 ==1)

    return n;

    else

    return n * multiply( n - 2);

    }

    a) If the method multiply(8) is called, what is the output? I got 8 as the output but I'm not sure... It's probably either 8 or 0...
    b)What do you notice about the bolded text in regards to programming? What is this programming concept called? Explain this concept. Back up your explaination by writing out each step in the code.
    -I know that the bolded terms are the same method. The concept is 'Recursion'. Recursion is when a method calls upon itself. But what does it mean when it asks "Back up your explaination by writing out each step in the code."??

    Thanks in advance for your help!


  2. #2
    Member snowguy13's Avatar
    Join Date
    Nov 2011
    Location
    In Hyrule enjoying a chat with Demise and Ganondorf
    Posts
    339
    My Mood
    Happy
    Thanks
    31
    Thanked 48 Times in 42 Posts

    Default Re: AP computer science questions

    But what does it mean when it asks "Back up your explaination by writing out each step in the code."??
    I think it means go through the method as if you were the program. So, what happens when multiply(8) is called? 8 is not equal to zero, and the remainder of 8 / 2 is not 1, either, so the program will go to the last option: 8 * multiply(8-2). What happens after that? You can go through the same thought process as I showed for 8 above and continue expanding the answer until you get a definite result.

    Doing that should not only answer part b, but show you the answer to part a too.
    Use highlight tags to help others help you!

    [highlight=Java]Your prettily formatted code goes here[/highlight]

    Using these tags makes your code formatted, and helps everyone answer your questions more easily!




    Wanna hear something funny?

    Me too.

Similar Threads

  1. need help in AP Computer Science!
    By eechord in forum Member Introductions
    Replies: 3
    Last Post: October 7th, 2011, 09:57 AM
  2. Frog jumping code (AP comp science help!)
    By CompScienceStudent1 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 21st, 2011, 05:42 PM
  3. Replies: 1
    Last Post: March 11th, 2011, 02:11 PM
  4. Using 1.5 jre/webstart on a computer with 1.6 installed
    By qman32 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 27th, 2011, 12:29 PM
  5. computer science help
    By hairyjewbear in forum Algorithms & Recursion
    Replies: 6
    Last Post: November 4th, 2010, 04:05 PM