Java hw help

cvillejin's Avatar, Join Date: Mar 2011
Newbie Member
Hi, I'm new to Java and I have no idea how to do this problem. I don't know what loops are or how to use them.

5. In mathematics, exponentiation of an is a multiplied by itself n times. For instance, 53 is 5*5*5, or 125. Define a method so it may be called using the following statement and finds the correct exponential operation:
int result = exponent(5,3);
You must use a loop in your method. Using the java.lang.math method pow() is not allowed. You can assume that the exponent is a positive, whole number. Note that the ^ operator does not perform exponentiation.
cvillejin's Avatar, Join Date: Mar 2011
Newbie Member
you can call the method what you want but I'm going to call it expo for now

public int expo(int n, int x){

int z, y;

y=n;
for(z=0: z<x; z++){
y=y*n;
}
return y;
}


is this correct?