Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Java hw help (http://www.go4expert.com/forums/java-hw-help-t25300/)

cvillejin 21Mar2011 07:43

Java hw help
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 21Mar2011 07:46

Re: Java hw help
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;

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

is this correct?

All times are GMT +5.5. The time now is 12:33.