From ab897ed84418bfedd2ed14a4ccedd0629fa29fa7 Mon Sep 17 00:00:00 2001 From: zhouxiang Date: Fri, 7 Aug 2020 23:01:02 +0800 Subject: [PATCH] function.java --- function.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 function.java diff --git a/function.java b/function.java new file mode 100644 index 0000000..92d62da --- /dev/null +++ b/function.java @@ -0,0 +1,26 @@ +public static double function(double x,int n){ + if(x==0) + { + return 0.0; + } + if(n>0) + { + return Pow(x,n); + } + else + { + return 1/Pow(x,-n); + } +} +public static double Pow(double x,int n){ + if(n==0) + return 1; + double tem=Pow(x,n/2); + if(n%2==0) + { + return tem*tem; + } + else{ + return tem*tem*x; + } +}