Write an iterative method to compute the power of x n for non-negative n.
What will be an ideal response?
```
public static int iterativePower(int x, int n)
{
int result = 1;
if(n < 0)
{
System.out.println("Illegal argument to power");
System.exit(0);
}
for(int i = 1; i <= n; ++i)
result = result * x;
return result;
}
```
Computer Science & Information Technology
You might also like to view...
A(n) ________ check box is equivalent to answering no
Fill in the blank(s) with correct word
Computer Science & Information Technology
The ________ specifies the cell containing the formula that produces a value for Solver to optimize
Fill in the blank(s) with correct word
Computer Science & Information Technology