Skip to main content
added 6 characters in body
Source Link
ant2009
  • 22.7k
  • 168
  • 440
  • 652
java version "1.8.0_92" 

I have the following code I am trying to understand and trace.

The part I don't understand is the * a at the end. When does that multiplication get called? And what is the return value of power1(a, n - 1);

Is it n - 1 * a

 public static double power1(double a, int n) { double result; if(n == 0) { return 1; } else { result = power1(a, n - 1) * a; return result; } } 
java version "1.8.0_92" 

I have the following code I am trying to understand and trace.

The part I don't understand is the * a at the end. When does that multiplication get called? And what is the return of power1(a, n - 1);

Is it n - 1 * a

 public static double power1(double a, int n) { double result; if(n == 0) { return 1; } else { result = power1(a, n - 1) * a; return result; } } 
java version "1.8.0_92" 

I have the following code I am trying to understand and trace.

The part I don't understand is the * a at the end. When does that multiplication get called? And what is the return value of power1(a, n - 1);

Is it n - 1 * a

 public static double power1(double a, int n) { double result; if(n == 0) { return 1; } else { result = power1(a, n - 1) * a; return result; } } 
Source Link
ant2009
  • 22.7k
  • 168
  • 440
  • 652

What is the return value of a recursive call

java version "1.8.0_92" 

I have the following code I am trying to understand and trace.

The part I don't understand is the * a at the end. When does that multiplication get called? And what is the return of power1(a, n - 1);

Is it n - 1 * a

 public static double power1(double a, int n) { double result; if(n == 0) { return 1; } else { result = power1(a, n - 1) * a; return result; } }