943,568 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1283
  • Java RSS
Aug 18th, 2008
0

Guys Need Some Help... What is the code for exponent in java?

Expand Post »
For:
Sum = Var1 + Var2
Difference = Var1 - Var2
Quotient = Var1 / Var2
Product = Var1 * Var2

What
Exponent = ?

Thanks in advance...
Similar Threads
Reputation Points: 5
Solved Threads: 0
Unverified User
ocreds is offline Offline
5 posts
since Jul 2008
Aug 18th, 2008
0

Re: Guys Need Some Help... What is the code for exponent in java?

I'm assuming you're not allowed to use the Math library or recursion.

If that's the case, use--

java Syntax (Toggle Plain Text)
  1.  
  2. static double power(double value, short exponent){
  3. if(exponent >= 0){ // if exponent is greater than or equal to zero...
  4. double result = 1; // set result to one
  5.  
  6. for(short i = 0; i < exponent; i++){ // doing something exponent times
  7. result = result * value; // result is assigned the number of itself times value
  8. }
  9.  
  10. return result; // return the result
  11. }else return 0; // exponent was less than 0 - return 0 for simplicity.
  12. }
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008
Aug 18th, 2008
0

Re: Guys Need Some Help... What is the code for exponent in java?

What if exponent is a double itself :-)
Last edited by ithelp; Aug 18th, 2008 at 5:03 am.
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Aug 18th, 2008
0

Re: Guys Need Some Help... What is the code for exponent in java?

Click to Expand / Collapse  Quote originally posted by ithelp ...
What if exponent is a double itself :-)
Then use the Math Library =P
Reputation Points: 392
Solved Threads: 108
Posting Shark
Alex Edwards is offline Offline
971 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Socket programming
Next Thread in Java Forum Timeline: just the copy the files from one plase to other place





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC