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 8382935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:02:42+00:00 2026-06-09T17:02:42+00:00

I built the following function that finds the nth root of a number in

  • 0

I built the following function that finds the nth root of a number in Python:

def find_root(base, nth_root, top = None, bottom = 0):
    if top == None: top = base

    half = (float(top) + float(bottom)) / 2.0 

    if half**nth_root == base or half == top or half == bottom:
        return half
    if half**nth_root > base:
        return find_root(base, nthRoot, half, bottom)
    if half**nth_root < base:
        return find_root(base, nthRoot, top, half)

As you can probably tell it is highly dependent upon default parameters. Is there (1) a better way to do this (I want it to be recursive), and (2) (this question probably has the same answer as 1) how can I do this in Java if the language does not support default parameters?

I’m new to Java and trying to work out the differences.

Thanks,

Michael G.

  • 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-09T17:02:43+00:00Added an answer on June 9, 2026 at 5:02 pm

    You can use method overloading to simulate default parameters:

    int find_root(int base, int nth_root) {
      return find_root(base, nth_root, -1, 0);
    }
    
    int find_root(int base, nth_root, int top, int bottom) {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following function, that loops through all table th s and builds
I have a need for a high-performance string hashing function in python that produces
I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I am building an XML document successfully with the following code: public function build($result)
I'm using the join_table function with Kohana's ORM to build a query. The following
How do I do the following using built-in modules only? I have a list
In the following code segment when built I keep breaking when adding the OnClickListener
I have following problem: I have built a tabbar application with 4 tabs. I
I get the following message: The project was not built due to File not
I am successfully executing the following query in SQL Server 2008 built into VS2008:

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.