Java beginers problem - n^k
<p>I'm having difficulty writing a program to solve this exercise from a Java text book:</p>

<blockquote>
  <p>Write a method raiseRealToPower that takes a floating-point value x and an integer
  k and returns xk. Implement your method so that it can correctly calculate the result
  when k is negative, using the relationship
  x^(-k) = 1 / x^k.  </p>
  
  <p>Use your method to display a table of values of πk for all values of k from –4 to 4.  </p>
</blockquote>

<p>I didn't done this part with PI, i know that, if my programs starts to work... this is what i done... tell me please, what is wrong.</p>

<pre><code>import acm.program.*;

public class vjezba55 extends ConsoleProgram {

    private static final double PI = 3.14159253;

    public void run() {
        double x = readDouble ("x: ");
        double k = readDouble ("k: ");
        println ("x^k = " + raiseDoublePower(x,k)); 
    }

    /* Method that counts x^k */
    private double raiseDoublePower (double x, double k){
        if (k &gt;= 0) {
            return Math.pow(x, k);
        }
        else {
            double total = 1;
            for (int i= 0; i&gt;k; i--) {
                total = (double) 1 / x;
            }
            return total;
        }
    }
}
</code></pre>
