View Single Post
  #2 (permalink)  
Old 04-23-2008, 09:23 AM
Eranga's Avatar
Eranga Eranga is offline
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,576
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Initially x = 5.0

Code:
double x = 5.0;
Call the power() with x = 5.0 and n = 4. Those parameters are moving on the loop as follows.
Code:
on if clause - still n > 1(n = 4) so, return 5.0 * power( 5.0, 3) on if clause - still n > 1(n = 3) so, 5.0 * return 5.0 * power( 5.0, 2) on if clause - still n > 1(n = 3) so, 5.0 * 5.0 * return 5.0 * power( 5.0, 1) skip else-if clause - n is not a negative on else clause 5.0 * 5.0 * 5.0 * return 5.0
So the answer is 625.0 for the first println(). Hope it's help
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Reply With Quote