| | |
Guys Need Some Help... What is the code for exponent in java?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I'm assuming you're not allowed to use the Math library or recursion.
If that's the case, use--
If that's the case, use--
java Syntax (Toggle Plain Text)
static double power(double value, short exponent){ if(exponent >= 0){ // if exponent is greater than or equal to zero... double result = 1; // set result to one for(short i = 0; i < exponent; i++){ // doing something exponent times result = result * value; // result is assigned the number of itself times value } return result; // return the result }else return 0; // exponent was less than 0 - return 0 for simplicity. }
What if exponent is a double itself :-)
Last edited by ithelp; Aug 18th, 2008 at 5:03 am.
![]() |
Similar Threads
- Java Client/Server (Java)
Other Threads in the Java Forum
- Previous Thread: Socket programming
- Next Thread: just the copy the files from one plase to other place
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows






