-----------------------------------
krishon
Sat Sep 27, 2003 11:18 am
find the root of one number to the other
-----------------------------------
well for example 3^1/4 which is the same as 4 root 3....wut function would i use to do that?
-----------------------------------
rizzix
Sat Sep 27, 2003 11:57 am
-----------------------------------
public static double Math.pow(double a, double b);
Which is defined in the java.lang package.. so no imports necessary.
Raises the first arg to the second, i.e: a^b
-----------------------------------
krishon
Sat Sep 27, 2003 6:32 pm
-----------------------------------
no not that one, its something else...here let me copy the question out, maybe it should make a difference.
Create a class called Number***. This class should have an instance variable,
called num, that will hold an integer value that will be the basis for all
operations using this object. You should have a constructor that initializes
num to hold the base value.
Your class should include methods that will use various methods from the
Math class to do the following:
a. A method that will return double the value of the num value. Call this
method double().
b. A method that will return square the value of the num value. Call this
method square().
c. A method that will return the square root of the num value. Call this
method root().
d. A method that will take a parameter and return the quotient of the
parameter divided by num rounded up to the nearest integer. Call this
method divUp().
e. A method that will return the value of num to the power of a parameter.
Call this method power().
i've done all but e
-----------------------------------
Tony
Sun Sep 28, 2003 1:11 am
-----------------------------------
Math.pow(num,argument) ?
-----------------------------------
krishon
Sun Sep 28, 2003 9:30 am
-----------------------------------
that one wuz for b....
-----------------------------------
rizzix
Sun Sep 28, 2003 11:18 am
-----------------------------------
whats wrong with this.. you using the same method: pow. but ur using it differently (sort of). And the question does not say anything about using a method more than once.
int a;
int square() {
return Math.pow((double)a, 2.0);
}
double power(int b) {
return Math.pow((double)a, (double)b);
}
-----------------------------------
krishon
Sun Sep 28, 2003 11:19 am
-----------------------------------
i dunno..maybe i interpreted the question wrong...ok i'll take ur way
-----------------------------------
rizzix
Sun Sep 28, 2003 11:30 am
-----------------------------------
woops i think i read ur question wrong. the methods are instance methods and affect (or work on) an instance variable..