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*2;
  17.  
  18.  
  19. for (int row = 1; row <= totalRows; row++) {
  20. for (int col = 1; col <= totalCols; col++) {
  21.  
  22. if (row <= n) {
  23.  
  24. if (col == totalCols) {
  25. System.out.print("e");
  26. } else {
  27. System.out.print("g");
  28. }
  29. } else if (row == n + 1) {
  30.  
  31. if (n == 3 && col == 2) {
  32. System.out.print("*");
  33. } else if (n != 3 && col == n + 1) {
  34. System.out.print("*");
  35. } else if (col == totalCols) {
  36. System.out.print("e");
  37. } else {
  38. System.out.print("g");
  39. }
  40. } else {
  41.  
  42. if (col <= 3) {
  43. System.out.print("*");
  44. } else {
  45. System.out.print("e");
  46. }
  47. }
  48. }
  49. System.out.println();
  50. }
  51. }
  52. }
Success #stdin #stdout 0.12s 54668KB
stdin
Standard input is empty
stdout
ggggggggge
ggggggggge
ggggggggge
ggggggggge
ggggggggge
ggggg*ggge
***eeeeeee