• Post Reply Bookmark Topic Watch Topic
  • New Topic

Another way to write a method  RSS feed

 
Erik Davies
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is all my code for a class i'm working on for a class below, but i'm having a issue with getDistanceFromMethod()

is there another way to rewrite this method without using the Math.pow? cause the second argument cant be a negative integer.

Its really got me stuck.

Thank you in advance,
Erik

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Erik,

certainly. Have a look at the Math class, where you will find the method 'sqrt'.
Remember: if you need the square of x, then x * x will do.

Greetz,
Piet
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Erik Davies wrote:is there another way to rewrite this method without using the Math.pow? cause the second argument cant be a negative integer.


remeber that a^(-b) is the same as 1/(a^b). So if you have a negative exponent, treat it like it is positive, then take the reciprocal.
 
Erik Davies
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help Piet and fred. I figured it out
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!