fork download
  1. /******************************************************************************
  2.  
  3.   Online Java Compiler.
  4.   Code, Compile, Run and Debug java program online.
  5. Write your code in this editor and press "Run" button to execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. public class Main
  10. {
  11. public static void pattern(int n){
  12. //first block
  13. for(int i=1;i<=n+2;i++){
  14. for(int j=1;j<=n+2;j++){
  15. if(j==(n+3)/2){
  16. System.out.print("e");
  17. }else{
  18. System.out.print(" ");
  19. }
  20. }
  21. System.out.println();
  22. }
  23.  
  24. //last block
  25.  
  26. for(int i=1;i<=n;i++){
  27. if(i==(n+1)/2){
  28. for(int j=1;j<=2*n+4;j++){
  29. if(j<=n+2){
  30. System.out.print("*");
  31. }else{
  32.  
  33. System.out.print("e");
  34. }
  35.  
  36. }
  37. }else{
  38. for(int j=1;j<=n+2;j++){
  39. System.out.print("*");
  40. }
  41. }
  42.  
  43. System.out.println();
  44.  
  45. }
  46. }
  47. public static void main(String[] args) {
  48.  
  49. //input here
  50. int n=8;
  51.  
  52.  
  53. if(n<=2){
  54. System.out.print("Please provide valid number");
  55. }else if(n%2==0){
  56. System.out.print("Provide odd number");
  57. }else{
  58. pattern(n);
  59. }
  60.  
  61. }
  62. }
Success #stdin #stdout 0.09s 52592KB
stdin
Standard input is empty
stdout
Provide odd number