fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. // System.out.println("Please enter odd number that should be greater than 2");
  14. Scanner sc = new Scanner(System.in);
  15. int n = sc.nextInt();
  16.  
  17. if(n >= 3 && n % 2 == 1){
  18. print(n);
  19. }else {
  20. System.out.print("Error!, Please enter odd number that should be greater than 2");
  21. }
  22.  
  23. }
  24.  
  25. public static void print(int n){
  26.  
  27. int k = (n+1)/2;
  28.  
  29. for(int i = 1; i<= k;i++){
  30. for(int sp = 1; sp <= k-1-(i-1);sp++){
  31. System.out.print(" ");
  32. }
  33.  
  34. for(int j = 1; j<= 2*i-1; j++){
  35. System.out.print("*");
  36. }
  37.  
  38. if(i == k-1 || i == k){
  39. for(int sp = 1; sp <= n+3; sp++){
  40. if(sp > i && sp < n+3){
  41. System.out.print(" ");
  42. }
  43. if(sp == n+3){
  44. System.out.print("e");
  45. }
  46. }
  47. }
  48.  
  49.  
  50. System.out.println();
  51. }
  52.  
  53. for(int i = 1; i<= n;i++){
  54. for(int sp = 1; sp <= (k-1)+ (n+3);sp++){
  55.  
  56. if(sp == k || sp == (k-1) + (n+3)){
  57. System.out.print("e");
  58. }
  59. else if(i == n && sp> k){
  60. System.out.print("e");
  61. }
  62. else System.out.print(" ");
  63. }
  64.  
  65.  
  66. System.out.println();
  67. }
  68.  
  69.  
  70. }
  71. }
Success #stdin #stdout 0.11s 56424KB
stdin
2
stdout
Error!, Please enter odd number that should be greater than 2