DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   java (http://www.daniweb.com/code/java.html)
-   -   alpe gulay's program to create a diamond using asterisk... (http://www.daniweb.com/code/snippet858.html)

alpe gulay java syntax
May 6th, 2008
.,'this program will simply creates a diamond using asterisk.,'
just try out this code i am sure you will be interested.!..
email me about your comment in this simple program!..help me if you know the easiest way to construct this kind of program..'

  1. import javax.swing.*;
  2. public class alpe_diamond_program
  3. {
  4. public static void main(String []args)
  5. {
  6. getri();
  7. }
  8.  
  9. public static void getri()
  10. {
  11. int x,y,z;
  12. int a=1;
  13. String out="\n";
  14.  
  15. int i=Integer.parseInt(JOptionPane.showInputDialog("Enter the size!"));
  16. if((i%2)!=0)
  17. {
  18.  
  19.  
  20. int in=(i/2)+(i%2);
  21. int bb=in-1;
  22. int b=bb+(bb-1);
  23.  
  24.  
  25. for(x=in;x>0;x--)
  26. {
  27.  
  28. for(y=x;y>1;y--)
  29. out+=" ";
  30.  
  31. for(z=0;z<a;z++)
  32. out+="*";
  33. a+=2;
  34. out+="\n";
  35. }
  36.  
  37.  
  38. for(x=0;x<in-1;x++)
  39. {
  40.  
  41. for(y=x;y>=0;y--)
  42. out+=" ";
  43.  
  44. for(z=0;z<b;z++)
  45. out+="*";
  46. b-=2;
  47. out+="\n";
  48. }
  49.  
  50.  
  51. System.out.print(out);
  52. getri();}
  53. else
  54. {
  55. System.out.print("I can't process!");
  56. getri();
  57. }
  58. }
  59. }
  60. //email me about your comment in this code!!!jalpex91@gmail.com