What is a non-defensive method in java?
<p>I am stuck on a mock exam question. </p>

<p>I have written the class below and it works.  However, within the body of the <code>powN</code> method, I need to use a <code>for(){}</code> loop. Also I need to use a non-defensive definition of <code>powN</code>. </p>

<p>Here are my questions. How can I use a for loop? What is a non-defensive method and how can it be used in <code>powN</code>?</p>

<pre><code>public class Power {
    private double x = 0;

    Power(double x) {
        this.x = x;
    }

    public double getX() {
        return x;
    }

    public double powN(int n) {
        return Math.pow(getX(), n);
    }

    public static void main(String[] args) {
        Power p = new Power(5.0);
        double d = p.powN(2);
        System.out.println(d);
    }
}
</code></pre>
