fork download
  1. import java.util.Scanner;
  2.  
  3. class Main{
  4. public static void main(String[] args){
  5. Scanner sc = new Scanner(System.in);
  6.  
  7. System.out.print("Enter a +ve odd number greater than 3 : ");
  8.  
  9. int n = sc.nextInt();
  10. if(n % 2 ==0 || n < 3){
  11. System.out.println("Only +ve odd numbers are allowed except 1.");
  12. } else {
  13. for(int i = 1; i<= n + 2; i++){
  14. for(int j = 1; j <= 2*n + 2; j++){
  15. if(i == (n+2)/2 + 1){
  16. if(j < n){
  17. System.out.print(" ");
  18. } else if(j == n){
  19. System.out.print("e");
  20. } else if(j <= 2 * n){
  21. System.out.print("*");
  22. }
  23. } else if(i != n + 2){
  24. if(j < n){
  25. System.out.print(" ");
  26. } else if (j == n){
  27. System.out.print("e");
  28. } else if(i == 1 && j > n){
  29. System.out.print("*");
  30. }
  31. } else {
  32. if(j == n){
  33. System.out.print("e");
  34. } else if(j < n)
  35. System.out.print("*");
  36. }
  37. }
  38. System.out.println();
  39. }
  40. }
  41. }
  42. }
Success #stdin #stdout 0.13s 56592KB
stdin
7
stdout
Enter a +ve odd number greater than 3 :       e*********
      e
      e
      e
      e*******
      e
      e
      e
******e