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. String str = br.readLine();
  14.  
  15. int n = str.length();
  16.  
  17. char[][] matrix = new char[n][2*n+1];
  18.  
  19. char[] chrArr = str.toCharArray();
  20.  
  21. // initializes the matrix with blank spaces
  22. for (int i = 0; i < n; i++) {
  23. for (int j = 0; j < 2*n+1; j++) {
  24. matrix[i][j] = ' ';
  25. }
  26. }
  27.  
  28. // build the two sides of the triangle
  29. for (int i = 0; i < n - 1; i++) {
  30. matrix[i][n-i] = chrArr[i];
  31. matrix[i][n+i] = chrArr[i];
  32. }
  33.  
  34. // last line, build the base of the triangle
  35. for (int i = 0; i < n; i++) {
  36. matrix[n-1][n-i] = chrArr[i];
  37. matrix[n-1][n+i] = chrArr[i];
  38. }
  39.  
  40. // print
  41. for (int i = 0; i < n; i++) {
  42. for (int j = 0; j < 2*n+1; j++) {
  43. System.out.print(matrix[i][j]);
  44. }
  45. System.out.print("\n");
  46. }
  47. }
  48. }
Success #stdin #stdout 0.11s 320512KB
stdin
STACKOVERFLOW
stdout
             S             
            T T            
           A   A           
          C     C          
         K       K         
        O         O        
       V           V       
      E             E      
     R               R     
    F                 F    
   L                   L   
  O                     O  
 WOLFREVOKCATSTACKOVERFLOW