Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:35:31+00:00 2026-06-13T12:35:31+00:00

So been studying for my past exam and come across this question which asks

  • 0

So been studying for my past exam and come across this question which asks what will the return value be if num = 7? Plugging it into BlueJ tells me 16, what does the func1 do to make it 16? How can the method declared be used again within the method? I searched but hard to find this exact example as it all comes up with just using methods normally.

Thanks,

public int func1(int num) 
{
  if ( num <= 2 ) return 1;
  return func1(num – 2) + num;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:35:32+00:00Added an answer on June 13, 2026 at 12:35 pm

    That is a recursive call to the same function you are using it in.

    So, func1(num – 2) will invoke the same function – public int func1(int num) with num = num - 2, until num >= 2

    So, you recursion goes like this: –

    func(n)
       calls func(n-2)
          calls func(n-4)
             .. so on
             calls func(1)
                returns 1
             returns 1 + 3 + ... + (n - 4)
          returns 1 + 3 + ... + (n - 4) + (n - 2) 
       returns 1 + 3 + ... + (n - 4) + (n - 2) + n
    

    UPDATE: – Generalized the above recursion, to let you figure out how it works.

    You can go through: – Recursion – Wiki Page

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been studying Scheme recently and come across a function that is defined in
I've been studying Python 3 recently and I have come across a conundrum: I
I've been studying soundex, metaphone and other string search techniques the past few days,
I've been studying because I have an exam and I don't have many problems
I've been studying fibers in Ruby, and the term semicoroutine has come up. What
I've been studying this: https://github.com/mikechambers/ExamplesByMesh/blob/master/JavaScript/QuadTree/src/QuadTree.js and I believe I understand the general idea about
I've been studying objective-c for a few days now. I keep coming across these
The past week or two I've been studying Maven, and I like it, but
I have been studying (old) 3D rendering techniques for the past weeks and think
I've been studying this for hours (2 days, actually) and just cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.