Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 find the root of one number to the other
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
krishon




PostPosted: Sat Sep 27, 2003 11:18 am   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Sat Sep 27, 2003 11:57 am   Post subject: (No subject)

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




PostPosted: Sat Sep 27, 2003 6:32 pm   Post subject: (No subject)

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




PostPosted: Sun Sep 28, 2003 1:11 am   Post subject: (No subject)

Math.pow(num,argument) ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
krishon




PostPosted: Sun Sep 28, 2003 9:30 am   Post subject: (No subject)

that one wuz for b....
rizzix




PostPosted: Sun Sep 28, 2003 11:18 am   Post subject: (No subject)

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.

code:

int a;

int square() {
    return Math.pow((double)a, 2.0);
}

double power(int b) {
    return Math.pow((double)a, (double)b);
}
krishon




PostPosted: Sun Sep 28, 2003 11:19 am   Post subject: (No subject)

i dunno..maybe i interpreted the question wrong...ok i'll take ur way
rizzix




PostPosted: Sun Sep 28, 2003 11:30 am   Post subject: (No subject)

woops i think i read ur question wrong. the methods are instance methods and affect (or work on) an instance variable..
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: