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. int n=5;
  13.  
  14. int m = n * 2;
  15.  
  16. int i = 1;
  17.  
  18. while (i <= n) {
  19.  
  20. int j = 1;
  21.  
  22. while (j < m) {
  23.  
  24. if (j >= i && j <= m - i) {
  25.  
  26. if (j <= n)
  27.  
  28. System.out.print (" " + (j - i + 1) + " ");
  29.  
  30. else
  31.  
  32. System.out.print (" " + (m - j - i + 1) + " ");
  33.  
  34. } else {
  35.  
  36. System.out.print (" ");
  37.  
  38. }
  39.  
  40. j = j + 1;
  41.  
  42. }
  43.  
  44. System.out.println ();
  45.  
  46. i = i + 1;
  47.  
  48. }
  49. }
  50. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
 1  2  3  4  5  4  3  2  1 
    1  2  3  4  3  2  1    
       1  2  3  2  1       
          1  2  1          
             1