1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
|
public class Main {
public static double exp(double x, int n) {
while (n > 1) {
x *= x;
n--;
}
return x;
}
public static void main(String[] args) {
System.out.println(exp(2, 3)); //hier werden x und n festgelegt.
//Ausgabe: 16.0
}
} |