-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFun38.java
More file actions
30 lines (24 loc) · 628 Bytes
/
Fun38.java
File metadata and controls
30 lines (24 loc) · 628 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
package fun;
public class Fun38 {
public static void main(String[] args) {
System.out.println(Power2(5, 0));
System.out.println(Power2(-5, 4));//-5*-5*-5*-5
System.out.println(Power2(5, 2));//-5*-5*-5*-5
}
public static double Power2(double a, double n) {
float result=1f;
double y = 1;
if (n > 0) {
for (int i = 1; i <= n; ++i)
{
result *= a;
}
} else if (a<0){
for (int i = 1; i <= n; ++i)
{
result *= a;
}
}
return result;
}
}