java - Raise Pi to -4 to 4 -


in homework have raise number pi -4 4. did 0 4 in negative numbers have problems. know problem when number negative no matter , program 1/pi, cant figure out how resolve this.

import acm.program.consoleprogram; public class raisrealtopower2 extends consoleprogram {      public void run () {        double n = 3.14159;        (int k = -4; k < 4; k++ ) {            println (n + " exp " + k + " " +  (raisepi (n, k)));        }          }             private double raisepi (double n, double k){        double total = n;        (double i=1; i<k; i++) {            total*=n;         }         if (k>0){            return total;          } else if (k==0) {            return 1.0 ;         } else {            return 1/total;               }     } } 

i add line @ start

if(k < 0) return 1/raisepi(n, -k); 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -