Author: BoXXi [ Fri Feb 06, 2004 7:39 pm ] Post subject: correction plz i was wonderin if anyone could help in by correcting my code.... i am doin a program with will print out the following diamond pattern y***** ******* y***** yy*** yyy* (the y is a space) the thing is the middlw line the bolded line ... .. if the user inputs the size 5 (it should lok like the pic) themiddle line is always +2 ... mine gives an extra so it gives like 8 stars .... and i am able to remove sumof the lines above .... import java.awt.*; import hsa.Console; public class Star { static Console c; public static void main (String [] args) { int n = 0; int size = 0; int space = 0, star = 1; Console c = new Console (); c.println ("Please enter an odd number from the range of 1-25"); n = c.readInt (); space = n / 2; star = n / 2; while (space != 0) { for (int i = 0 ; i < space ; i++) c.print (" "); for (int i = 0 ; i < star ; i++) c.print ("*"); for (int i = 0 ; i < space ; i++) c.print (" "); space--; star = star +2; c.print ("\n"); } for (int i = 0 ; i < star ; i++); c.print ("*"); //middle line for (int i = 0 ; i < star ; i++) c.print ("*"); c.print ("\n"); while (star > 1) { space++; star = star - 2; for (int i = 0 ; i < space ; i++) c.print (" "); for (int i = 0 ; i < star ; i++) c.print ("*"); for (int i = 0 ; i < space ; i++) c.print (" "); c.print ("\n"); } } }

Author:  Paul [ Fri Feb 06, 2004 11:26 pm ]
Post subject:

I tried to help, but I couldn't run the program, cause
 code: import hsa.Console;

I can't seem to import this, is this a standard thing that comes with JDK?
Im a noob, and I run java out of MS Dos prompt so...
I probably could help you a bit if I could run it and see what its like.

 Author: BoXXi [ Sat Feb 07, 2004 11:29 am ] Post subject: yeah it is a standard thing

 Author: rizzix [ Sat Feb 07, 2004 11:38 am ] Post subject: not it isn't.. its a package that comes with the software they use

 Author: Prince [ Sat Feb 07, 2004 1:43 pm ] Post subject: its standard if ur usin Ready by good ol' HoltSoft, the ppl that brought us Turing ..... and is this topic not almost the exactly same thing i put up Author:  BoXXi [ Sat Feb 07, 2004 6:48 pm ]
Post subject:

i am not able to get rid of the first two lines ... rest everything is fine .... can anyone help me .... !!!!!  code: import java.awt.*; import hsa.Console; public class Star {     static Console c;     public static void main (String [] args)     {         int n = 0;         int size = 0;         int space = 0, star = 1;         Console c = new Console ();         c.println ("Please enter an odd number from the range of 1-25");         n = c.readInt ();         space = n / 2;         star = n / 2;         while (space != 0)         {             for (int i = 0 ; i < space ; i++)                 c.print (" ");             for (int i = 0 ; i < star ; i++)                 c.print ("*");             for (int i = 0 ; i < space ; i++)                 c.print (" ");             space--;             star = star + 2;             c.print ("\n");         }         for (int i = 1 ; i < star ; i++);         c.print ("*");         for (int i = 1 ; i < star ; i++) //midle line             c.print ("*");         c.print ("\n");         while (star > 1)         {             space++;             star = star - 2;             for (int i = 0 ; i < space ; i++)                 c.print (" ");             for (int i = 0 ; i < star ; i++)                 c.print ("*");             for (int i = 0 ; i < space ; i++)                 c.print (" ");             c.print ("\n");         }     } }

Mod edit: use the [ code ] tags, makes it easier to read

 Author: Dark Mist [ Sun Feb 08, 2004 3:11 pm ] Post subject: i dont understand wat u are doin .... instead of doin that way y wond u just simply break it into two part one which prints out the first two lines and the second that prints out the other lines ....

 Author: Paul [ Sun Feb 08, 2004 3:13 pm ] Post subject: Help you with what and why did you post here in this thread?

Author:  rizzix [ Sun Feb 08, 2004 4:01 pm ]
Post subject:

well.. i've posted this before in some other thread.. but anyways..:

the for-loop draws out the lower part of the diamond. if u reverse the algorithm (which i haven't done) u can possibly create the upper part similarly

 code: int w = 9;     // width of diamond print    repeat " "  by  w - ((w - 2) mod w);  // might have to replace these print    repeat "*"  by  (w - 2) * 2;          // three lines with better code println;                                       // for (int i = w - 1; i >= 0; i--) {     print    repeat  " "  by   w - (i mod w);     print    repeat  "*"  by   i * 2;     println; }

PS: note this is not valid java code.. just pseudocode. but you should be able to make sense of it

 :