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

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 5
Reputation: ocreds has a little shameless behaviour in the past 
Solved Threads: 0
ocreds ocreds is offline Offline
Newbie Poster

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

 
0
  #1
Aug 18th, 2008
For:
Sum = Var1 + Var2
Difference = Var1 - Var2
Quotient = Var1 / Var2
Product = Var1 * Var2

What
Exponent = ?

Thanks in advance...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

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

 
0
  #2
Aug 18th, 2008
I'm assuming you're not allowed to use the Math library or recursion.

If that's the case, use--

  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. }
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,836
Reputation: ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all ithelp is a name known to all 
Solved Threads: 119
ithelp's Avatar
ithelp ithelp is offline Offline
Posting Virtuoso

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

 
0
  #3
Aug 18th, 2008
What if exponent is a double itself :-)
Last edited by ithelp; Aug 18th, 2008 at 5:03 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 973
Reputation: Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough Alex Edwards is a jewel in the rough 
Solved Threads: 107
Alex Edwards's Avatar
Alex Edwards Alex Edwards is offline Offline
Posting Shark

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

 
0
  #4
Aug 18th, 2008
Originally Posted by ithelp View Post
What if exponent is a double itself :-)
Then use the Math Library =P
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC