fork download
  1. import java.util.Scanner;
  2.  
  3. class Ideone {
  4.  
  5. public static void main(String[] args) {
  6. // Scanner scanner = new Scanner(System.in);
  7. // System.out.print("Enter an integer (e.g., 3 or 5): ");
  8. // int n = scanner.nextInt();
  9. // printPattern(n);
  10. // scanner.close();
  11. printPattern(3);
  12. }
  13.  
  14. public static void printPattern(int n) {
  15. // Upper part of the pattern
  16. for (int i = 0; i < n - 1; i++) {
  17. // Print 'g' characters
  18. for (int j = 0; j < 2 * n; j++) {
  19. System.out.print('g');
  20. }
  21. // Print 'e' characters
  22. for (int j = 0; j < n; j++) {
  23. System.out.print('e');
  24. }
  25. System.out.println();
  26. }
  27.  
  28. // Middle and bottom part of the pattern
  29. int numRowsBottom = n / 2 + 2;
  30. int maxStars = 2 * (n / 2) + 1;
  31. int gColumns = 2 * n;
  32.  
  33. for (int i = 0; i < numRowsBottom; i++) {
  34. // Print 'g' characters on the left
  35. for (int j = 0; j < gColumns; j++) {
  36. System.out.print('g');
  37. }
  38.  
  39. // Print the stars pyramid and spaces
  40. int numStars = 2 * i + 1;
  41. int numSpacesStars = (maxStars - numStars) / 2;
  42.  
  43. for (int j = 0; j < numSpacesStars; j++) {
  44. System.out.print(' ');
  45. }
  46.  
  47. for (int j = 0; j < numStars; j++) {
  48. System.out.print('*');
  49. }
  50.  
  51. for (int j = 0; j < numSpacesStars; j++) {
  52. System.out.print(' ');
  53. }
  54.  
  55. // Print 'e' characters on the right
  56. for (int j = 0; j < n; j++) {
  57. System.out.print('e');
  58. }
  59.  
  60. System.out.println();
  61. }
  62.  
  63. // Last row of stars and 'e's
  64. for (int i = 0; i < 2 * n; i++) {
  65. System.out.print('*');
  66. }
  67. for (int i = 0; i < n; i++) {
  68. System.out.print('e');
  69. }
  70. System.out.println();
  71. }
  72. }
Success #stdin #stdout 0.1s 52728KB
stdin
Standard input is empty
stdout
ggggggeee
ggggggeee
gggggg * eee
gggggg***eee
gggggg*****eee
******eee