| | |
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 |
android api applet application apps array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor crashcourse database draw eclipse ee error eventlistener exception fractal free game gis givemetehcodez graphics gui html ide image input integer integration j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jni jpanel jtree julia jvm linux list loop machine map method methods migrate mobile netbeans newbie oracle parsing physics plazmic print problem program programming project radio recursion scanner screen server service set sharepoint size smart sms socket software sort sortedmaps sql string swing textfield threads tree trolltech unlimited utility webservices windows






