Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package chapter8;
- public class Numeric
- {
- public static double intPower(double x, int n)
- {
- double answer;
- if(n > 0 && n % 2 != 0)
- {
- double intermediate;
- intermediate = Math.pow(x, n-1);
- answer = intermediate * x;
- }
- if(n < 0){
- answer = 1 / (Math.pow(x, n));
- }
- if(n > 0 && n % 2 == 0)
- {
- double mediator;
- mediator = Math.pow(x, n / 2);
- answer = Math.pow(mediator, 2);
- }
- return answer;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement