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

  • Home
  • SEARCH
  • 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 8804899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:43:38+00:00 2026-06-14T01:43:38+00:00

{ System.out.println (base + to the + i + power = + power(base, i));

  • 0
 {
System.out.println (base + " to the " + i + " power =  " + 
                          power(base, i));   
}

    public static double power(double baseNum, int exp) 
    {
        if (exp == 0)
            return 1;
        else
            return baseNum * power(baseNum, --exp); 
    }  

Quick question, the method above called “power” somehow returns the solution to an answer when it returns “1”. So if I passed the parameters to calculate 2 ^ 5, RETURN 1 somehow turns into 32.0. What exactly is going on here? how does “1” become 32.0?

  • 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-14T01:43:40+00:00Added an answer on June 14, 2026 at 1:43 am
    else
        return baseNum * power(baseNum, --exp);
    

    That code right there. When one of the power functions is returning 1, it actually was called by this. So it’s going to be like:

    return baseNum * power(baseNum, --exp);
    

    And the power returned 1, so:

    return baseNum * 1;
    

    And baseNum would be 32.0 in that case.

    Recursion.

    Better explanation: http://pastebin.com/raw.php?i=dHTnSPuY (my comment begin with an @ sign)

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

Sidebar

Related Questions

class Base { int i = 99; public void amethod() { System.out.println(Base.amethod()); } Base()
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
I was trying following example: class BaseClass { public void methodA(Class<?> cl) { System.out.println(Base.methodA());
class Base { public void add() { System.out.println(Base ADD); } void subtract() { throw
class base { public void superMethod() { System.out.println(Hello i m a super class method);
package P1; public class Base { private void pri( ) { System.out.println(Base.pri()); } void
public abstract class Master { public void printForAllMethodsInSubClass() { System.out.println (Printing before subclass method
Please refer to the Java code below: class Base{ Base(){ System.out.println(Base Constructor); method(); }
abstract class A { public void methodA() { System.out.println(methodA); methodB(); showName(); } public abstract
I'm working with a code base containing over 2500 System.out.println statements. Besides refactoring, is

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.