fork download
  1. class Main
  2. {
  3. public static void main(String[] args)
  4. {
  5. stars();
  6. }
  7.  
  8. static void stars()
  9. {
  10. final int MAX_WIDTH = 7;
  11.  
  12. for (int i = 0; i < 7; ++i)
  13. {
  14. int width;
  15.  
  16. if (i < 3) width = MAX_WIDTH - i * 2;
  17. else if (i > 3) width = (i - 3) * 2 + 1;
  18. else width = 1;
  19.  
  20. // Before spaces
  21.  
  22. for (int j = 0; j < (MAX_WIDTH - width) / 2; ++j)
  23. {
  24. System.out.print(" ");
  25. }
  26.  
  27. // Stars
  28.  
  29. for (int j = 0; j < width; ++j)
  30. {
  31. System.out.print("*");
  32. }
  33.  
  34. // After spaces
  35.  
  36. for (int j = 0; j < (MAX_WIDTH - width) / 2; ++j)
  37. {
  38. System.out.print(" ");
  39. }
  40.  
  41. System.out.println();
  42. }
  43. }
  44. }
Success #stdin #stdout 0.03s 245632KB
stdin
Standard input is empty
stdout
*******
 ***** 
  ***  
   *   
  ***  
 ***** 
*******