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. render();
  13. }
  14.  
  15. private static final char fillChar = '*';
  16. private static final int BaseLength = 64;
  17.  
  18. public static void render(){
  19. int i;
  20.  
  21. // puncak
  22. for(i = 2; i <= 6; i+=2){
  23. centerize(i);
  24. }
  25.  
  26. // bawah puncak
  27. for(i = 24; i >= 20; i-=2){
  28. centerize(i);
  29. }
  30.  
  31. // tiang
  32. for(i = 0; i < 24; i++){
  33. centerize(6);
  34. }
  35.  
  36. // dasar tiang
  37. for(i = 62; i >= 26; i -= 6){
  38. centerize(i);
  39. }
  40.  
  41. // dasar tiang dengan bolongan tengah
  42. for(i = 16; i >= 10; i -= 6){
  43. centerize(BaseLength, i, 4);
  44. }
  45.  
  46. // pondasi bawah
  47. for(i = 62; i <= 64; i +=2 ){
  48. centerize(i);
  49. }
  50. }
  51.  
  52. public static void centerize(int fill){
  53. centerize(BaseLength, fill, 0);
  54. }
  55.  
  56. public static void centerize(int length, int fill, int centerspace){
  57. int fillLen = fill + centerspace;
  58. int paddLen = (length - fillLen) / 2;
  59.  
  60. String padd = (paddLen == 0) ? "" : String.format("%" + paddLen + "s", " ");
  61. String print = "";
  62. if(centerspace == 0) {
  63. print = String.format("%" + fill + "s", fillChar).replace(' ', fillChar);
  64. } else {
  65. fillLen -= centerspace;
  66. String centerFill = String.format("%" + centerspace + "s", " ");
  67. print = String.format("%" + (fill/2) + "s", fillChar).replace(' ', fillChar);
  68. print = String.format("%s%s%s", print, centerFill, print);
  69. }
  70.  
  71. System.out.println(padd + print + padd);
  72. }
  73. }
Success #stdin #stdout 0.12s 320448KB
stdin
Standard input is empty
stdout
                               **                               
                              ****                              
                             ******                             
                    ************************                    
                     **********************                     
                      ********************                      
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
                             ******                             
 ************************************************************** 
    ********************************************************    
       **************************************************       
          ********************************************          
             **************************************             
                ********************************                
                   **************************                   
                      ********    ********                      
                         *****    *****                         
 ************************************************************** 
****************************************************************