User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 373,577 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
May 6th, 2008
Views: 900
.,'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..'
java Syntax | 2 stars
  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
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 7:48 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC