-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFun39.java
More file actions
41 lines (30 loc) · 826 Bytes
/
Fun39.java
File metadata and controls
41 lines (30 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package fun;
public class Fun39 {
public static void main(String[] args) {
System.out.println(Power3(2, 2));
System.out.println(Power3(2, 2.5));
}
public static double Power3(double a, double n) {
int d = (int) (n / 1);
if (n - d == 0) return Power1((int) a, (int) n);
else return Power2(a, n);
}
public static int Power1(int a, int b) {
int result=1;
if (b > 0) {
for (int i = 1; i <= b; ++i) {
result *= a;
}
} else if (a < 0) {
for (int i = 1; i <= b; ++i) {
result *= a;
}
}
return result;
}
public static double Power2(double a, double n) {
double pow = 0;
pow = Math.pow(a, n);
return pow;
}
}