fork 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 void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. int lim = 5;
  14. int spaceLim = lim*2;
  15.  
  16. for (int i=0; i < lim; i++){ // Number of rows is the key here (pow 2)
  17.  
  18. String s = "%" + spaceLim + "s";
  19. System.out.printf(s, "");
  20. if (i == 0){
  21. System.out.print(1);
  22. }
  23. else{
  24. for (int j=0; j<i; j++) {
  25. System.out.printf("%1.0f ",(Math.pow(2.0, (double)(j))));
  26. }
  27.  
  28. for (int j=i; j>=0; j--){
  29. System.out.printf("%1.0f ", (Math.pow(2.0, (double)(j))));
  30. }
  31.  
  32. }
  33. System.out.println();
  34. spaceLim -= 2;
  35. }
  36. }
  37. }
Success #stdin #stdout 0.11s 320256KB
stdin
Standard input is empty
stdout
          1
        1 2 1 
      1 2 4 2 1 
    1 2 4 8 4 2 1 
  1 2 4 8 16 8 4 2 1