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 the input number (n): ");
  8. // int n = scanner.nextInt();
  9. // scanner.close();
  10.  
  11. printPattern(5);
  12. }
  13.  
  14. public static void printPattern(int n) {
  15. int totalRows = n + 2;
  16. int totalCols = (n == 3) ? 6 : (n + 5);
  17.  
  18. for (int row = 1; row <= totalRows; row++) {
  19. for (int col = 1; col <= totalCols; col++) {
  20.  
  21. if (row <= n) {
  22.  
  23. if (col == totalCols) {
  24. System.out.print("e");
  25. } else {
  26. System.out.print("g");
  27. }
  28. } else if (row == n + 1) {
  29.  
  30. if (n == 3 && col == 2) {
  31. System.out.print("*");
  32. } else if (n != 3 && col == n + 1) {
  33. System.out.print("*");
  34. } else if (col == totalCols) {
  35. System.out.print("e");
  36. } else {
  37. System.out.print("g");
  38. }
  39. } else {
  40.  
  41. if (col <= 3) {
  42. System.out.print("*");
  43. } else {
  44. System.out.print("e");
  45. }
  46. }
  47. }
  48. System.out.println();
  49. }
  50. }
  51. }
Success #stdin #stdout 0.09s 54712KB
stdin
Standard input is empty
stdout
ggggggggge
ggggggggge
ggggggggge
ggggggggge
ggggggggge
ggggg*ggge
***eeeeeee