First I will give an outline what I have to do.
The example below covers the case of n>0. You need to cover both >0 and <0.
class Power{
float power (float x,long n){
float pow=1;
for(int i=0;i<n;++i)
pow=pow*x;
}
return pow;
}
}
Now for my code
My question is about the i>n statement of where to place it and I keep getting the error power(float,long) is already defined in Powerimport java.util.Scanner; public class Power { //variables declarations int base; int power; int pow; public Power (int a, int n) //constructors for powers { base = a; power = n; } public int getBase() { return base; } public int getExponent() { return power; } float power (float a,long n) //test for < { float pow=1; for(int i=0;i<n;++i) pow=pow*a; return pow; } float power (float a,long n) //test for > { float pow=1; for(int i=1;i>n;++i) pow=pow*a; return pow; } }
float power (float a,long n) //test for >
I really need help with this part, I just can not understand what to do here. Thanks