fork(4) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static double power(double x, int n) {
  11. if (n == 0) return 1;
  12. if (n == 1) return x;
  13. double pHalf = power(x, n/2);
  14. if (n%2 == 0) {
  15. return pHalf*pHalf;
  16. } else {
  17. return x*pHalf*pHalf;
  18. }
  19. }
  20. public static void main (String[] args) throws java.lang.Exception {
  21. for (int i = 0 ; i != 20 ; i++)
  22. System.out.println(power(2, i));
  23. }
  24. }
Success #stdin #stdout 0.1s 320576KB
stdin
Standard input is empty
stdout
1.0
2.0
4.0
8.0
16.0
32.0
64.0
128.0
256.0
512.0
1024.0
2048.0
4096.0
8192.0
16384.0
32768.0
65536.0
131072.0
262144.0
524288.0