fork download
  1.  
  2. import java.util.Scanner;
  3.  
  4. class Ideone {
  5.  
  6. public static void main(String[] args) {
  7. // Scanner scanner = new Scanner(System.in);
  8. // System.out.print("Enter an integer (e.g., 3): ");
  9. // int n = scanner.nextInt();
  10. // printPattern(n);
  11. // scanner.close();
  12.  
  13. printPattern(3);
  14. }
  15.  
  16. public static void printPattern(int n) {
  17. int totalRows = n + 2;
  18. int totalCols = n * 2;
  19.  
  20. // Top section: rows with spaces and 'e's
  21. for (int i = 0; i < n; i++) {
  22. // Print spaces
  23. for (int j = 0; j < totalCols - n; j++) {
  24. System.out.print(" ");
  25. }
  26. // Print 'e's
  27. for (int j = 0; j < n; j++) {
  28. System.out.print("e");
  29. }
  30. System.out.println();
  31. }
  32.  
  33. // Middle section: pyramid of stars
  34. for (int i = 0; i < n / 2 + 1; i++) {
  35. // Print leading spaces
  36. int numLeadingSpaces = totalCols - n - (n / 2) - 1 - i;
  37. printChars(' ', numLeadingSpaces);
  38.  
  39. // Print stars
  40. int numStars = 2 * i + 1;
  41. printChars('*', numStars);
  42.  
  43. // Print trailing spaces
  44. int numTrailingSpaces = (n / 2 + 1) - i - 1;
  45. printChars(' ', numTrailingSpaces);
  46.  
  47. // Print 'e's
  48. int numEs = n - i;
  49. printChars('e', numEs);
  50.  
  51. System.out.println();
  52. }
  53.  
  54. // Bottom section: full line of stars
  55. printChars('*', totalCols - n);
  56. printChars('e', n);
  57. System.out.println();
  58. }
  59.  
  60. // Helper method to print a character a specified number of times
  61. private static void printChars(char character, int count) {
  62. for (int i = 0; i < count; i++) {
  63. System.out.print(character);
  64. }
  65. }
  66. }
Success #stdin #stdout 0.12s 54672KB
stdin
Standard input is empty
stdout
   eee
   eee
   eee
 * eee
***ee
***eee