Factorial iteration java -


pocould explain piece of code me?? power function using iteration

  public static int iterate(int a, int n)  {     int ;     int result = 1 ;      for(i = 0 ; < n ; i++){         result = result*a ;                   }     return result ;  } 

it helps know definition of factorial:

0! = 1 1! = 1 2! = 2*1 = 2 3! = 3*2*1 = 6 4! = 4*3*2*1 = 24 n! = n*(n-1)*(n-2)*...*2*1 

see pattern?

  1. start result = 1
  2. loop , multiply index
  3. return result

what posted looks more a^n = a*a*a...*a me, not factorial.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -