fork download
  1. class Ideone {
  2.  
  3. public static void main (String[] args) throws java.lang.Exception
  4. {
  5. int n = 3; // Example input
  6.  
  7. printCustomPattern(n);
  8. }
  9.  
  10. public static void printCustomPattern(int n) {
  11.  
  12. for (int i = 1; i <= n; i++) {
  13. for (int j = 1; j <= 5; j++) {
  14. if (j == 5) {
  15. System.out.print("e");
  16. } else {
  17. System.out.print("g");
  18. }
  19. }
  20. System.out.println(); // Move to the next line
  21. }
  22.  
  23. // Last 2 levels (star pattern)
  24. for (int i = 1; i <= 2; i++) {
  25. for (int j = 1; j <= 5; j++) { // Example: 5 stars per line
  26. System.out.print("*");
  27. }
  28. System.out.println(); // Move to the next line
  29. }
  30. }
  31. }
Success #stdin #stdout 0.08s 54720KB
stdin
Standard input is empty
stdout
gggge
gggge
gggge
*****
*****