fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class Ideone {
  9.  
  10. public static void main(String[] args) {
  11. // Scanner scanner = new Scanner(System.in);
  12. // System.out.print("Enter the input number (n): ");
  13. // int n = scanner.nextInt();
  14. // scanner.close();
  15.  
  16. printPattern(3);
  17. }
  18.  
  19. public static void printPattern(int n) {
  20. int totalRows = n + 2;
  21. int totalCols = n*2;
  22.  
  23.  
  24. for (int row = 1; row <= totalRows; row++) {
  25. for (int col = 1; col <= totalCols; col++) {
  26.  
  27. if (row <= n) {
  28.  
  29. if (col == totalCols) {
  30. System.out.print("e");
  31. } else {
  32. System.out.print("g");
  33. }
  34. } else if (row == n + 1) {
  35.  
  36. if (n == 3 && col == 2) {
  37. System.out.print("*");
  38. } else if (n != 3 && col == n + 1) {
  39. System.out.print("*");
  40. } else if (col == totalCols) {
  41. System.out.print("e");
  42. } else {
  43. System.out.print("g");
  44. }
  45. } else {
  46.  
  47. if (col <= 3) {
  48. System.out.print("*");
  49. } else {
  50. System.out.print("e");
  51. }
  52. }
  53. }
  54. System.out.println();
  55. }
  56. }
  57. }
Success #stdin #stdout 0.07s 52668KB
stdin
Standard input is empty
stdout
ggggge
ggggge
ggggge
g*ggge
***eee