exponents without math.pow using for loop (in java)
<p>i need to take 2 inputted numbers and calculate variable 1 to the power of variable 2 is without using math.pow and using a for loop. This is what i have now</p>

<pre><code>    Scanner in = new Scanner(System.in);
System.out.print("Please enter your base: ");
int base = in.nextInt();
System.out.print("Please enter your exponent: ");
int power = in.nextInt();

    int result = mathPower(base, power);
    System.out.println(base + " to the power of " + power  + " is " + result + ".");



}

public static int mathPower(int a, int b) 
{

    int result = a;

    if (b == 0) {

            result = 1;

        }

    if (b &lt; 0) {

           a = (1 / a);
           b = -b;
        }

    for (a = 1; a &lt; b; a++) {

        result = result * a;
        return result;

    }

    return result;
}
</code></pre>

<p>}</p>

<p>It only seems to work if the exponent is 0, otherwise it just displays the a value. I need both positive and negative exponents. Thanks in advance!</p>