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. /* 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. // your code goes here
  13.  
  14. int i,j,n;
  15.  
  16. Scanner sc=new Scanner(System.in);
  17.  
  18. n=sc.nextInt();
  19. if(n>0 && n>=3 && n%2!=0 ){
  20. //System.out.println("Hiii");
  21.  
  22. for(i=0;i<n-1;i++){
  23. for(j=0;j<2*n-1;j++){
  24. System.out.print(" ");
  25. }
  26. for(j=0;j<1;j++)
  27. {
  28. System.out.print("*");
  29. }
  30. System.out.println();
  31. }
  32. for(i=0;i<n+2;i++){
  33. for(j=0;j<n;j++){
  34. System.out.print(" ");
  35.  
  36. }
  37. for(j=0;j<n;j++){
  38. // if(j>=0 && i<1){
  39. // System.out.print(" ");
  40. // }
  41. // else{
  42. if(j<1){
  43. System.out.print("*");
  44. }
  45. }
  46. System.out.println();
  47. }
  48. for(i=0;i<n-1;i++){
  49. for(j=0;j<2*n-1;j++){
  50. System.out.print(" ");
  51.  
  52. }
  53. for(j=0;j<1;j++)
  54. {
  55. System.out.print("*");
  56. }
  57. System.out.println();
  58. }
  59. }
  60. else{
  61. System.out.println("Please enter a odd number");
  62. }
  63. }}
Success #stdin #stdout 0.12s 56644KB
stdin
3
stdout
     *
     *
   *
   *
   *
   *
   *
     *
     *