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. int n = 3;
  12.  
  13. if(n < 0 ){
  14. System.out.println("number can't be less than zero");
  15. return;
  16. }
  17.  
  18. if(n == 1){
  19. System.out.println("Number Should Not Be 1");
  20. return ;
  21. }
  22. boolean state = true;
  23.  
  24. for(int i = 2 ; i <=n ; i++){
  25. if(n%i == 0){
  26. state = true;
  27. }
  28. }
  29.  
  30. if(state == false){
  31. System.out.println("Number Should be Odd except 1");
  32. return ;
  33. }
  34.  
  35. printPattern(n);
  36. }
  37.  
  38. public static void printPattern(int n) {
  39. int totalRows = n + 2;
  40. int totalCols = n*2;
  41.  
  42.  
  43. for (int row = 1; row <= totalRows; row++) {
  44. for (int col = 1; col <= totalCols; col++) {
  45.  
  46. if (row <= n) {
  47.  
  48. if (col == totalCols) {
  49. System.out.print("e");
  50. } else {
  51. System.out.print(" ");
  52. }
  53. } else if (row == n + 1) {
  54.  
  55. if (n == 3 && col == 2) {
  56. System.out.print("*");
  57. } else if (n != 3 && col == n + 1) {
  58. System.out.print("*");
  59. } else if (col == totalCols) {
  60. System.out.print("e");
  61. } else {
  62. System.out.print(" ");
  63. }
  64. } else {
  65.  
  66. if (col <= 3) {
  67. System.out.print("*");
  68. } else {
  69. System.out.print("e");
  70. }
  71. }
  72. }
  73. System.out.println();
  74. }
  75. }
  76. }
Success #stdin #stdout 0.11s 54608KB
stdin
Standard input is empty
stdout
     e
     e
     e
 *   e
***eee