title: How to write a function that can calculate power in Java. No loops
body: <p>I've been trying to write a simple function in Java that can calculate a number to the nth power without using loops.<br>
  I then found the <em>Math.pow(a, b)</em> class... or method still can't distinguish the two am not so good with theory. So i wrote this..</p>
  
  <pre><code>public static void main(String[] args) {
  
      int a = 2;
  
      int b = 31;
  
      System.out.println(Math.pow(a, b));
  
      }
  </code></pre>
  
  <p>Then i wanted to make my own <em>Math.pow</em> without using loops i wanted it to look more simple than loops, like using some type of <em>Repeat</em> I made a lot of research till i came across the <em>commons-lang3</em> package i tried using <em>StringUtils.repeat</em><br>
  So far I think this is the Syntax:-</p>
  
  <pre><code>public static String repeat(String str, int repeat)
      StringUtils.repeat("ab", 2);
  </code></pre>
  
  <p>The <strong>problem</strong> i've been facing the <strong>past 24hrs</strong> or more is that <em>StringUtils.repeat(String str, int 2);</em> repeats strings not out puts or numbers or calculations.<br>
  Is there anything i can do to overcome this or is there any other better approach to creating a function that calculates powers?<br>
  <strong>without using loops or Math.pow</strong>  </p>
  
  <p>This might be funny but it took me while to figure out that <em>StringUtils.repeat</em> only repeats strings this is how i tried to overcome it. incase it helps</p>
  
  <pre><code> public static int repeat(int cal, int repeat){
       cal = 2+2;
       int result = StringUtils.repeat(cal,2);
       return result;
  }  
  </code></pre>
  
  <p>can i not use recursion maybe some thing like this </p>
  
  <pre><code>public static RepeatThis(String a)
  {
       System.out.println(a);
       RepeatThis(a);
  } 
  </code></pre>
  
  <p><em>just trying to understand java in dept thanks for all your comments even if there were syntax errors as long as the logic was understood that was good for me</em> :)</p>