Author |
Message |
BoXXi
|
Posted: 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");
}
}
} |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Paul
![](http://i12.photobucket.com/albums/a207/paulbian/DDRDuck.png)
|
Posted: Fri Feb 06, 2004 11:26 pm Post subject: (No 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. |
|
|
|
|
![](images/spacer.gif) |
BoXXi
|
Posted: Sat Feb 07, 2004 11:29 am Post subject: (No subject) |
|
|
yeah it is a standard thing |
|
|
|
|
![](images/spacer.gif) |
rizzix
|
Posted: Sat Feb 07, 2004 11:38 am Post subject: (No subject) |
|
|
not it isn't.. its a package that comes with the software they use |
|
|
|
|
![](images/spacer.gif) |
Prince
![](http://www.angelfire.com/hiphop3/m-unit_hustla/images/fxckpare.jpg)
|
Posted: Sat Feb 07, 2004 1:43 pm Post subject: (No 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 ![Confused Confused](images/smiles/icon_confused.gif) |
|
|
|
|
![](images/spacer.gif) |
BoXXi
|
|
|
|
![](images/spacer.gif) |
Dark Mist
![](http://files.themexp.org/screenshots/wp/s26313.jpg)
|
Posted: Sun Feb 08, 2004 3:11 pm Post subject: (No 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 .... |
|
|
|
|
![](images/spacer.gif) |
Paul
![](http://i12.photobucket.com/albums/a207/paulbian/DDRDuck.png)
|
Posted: Sun Feb 08, 2004 3:13 pm Post subject: (No subject) |
|
|
Help you with what and why did you post here in this thread? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
rizzix
|
Posted: Sun Feb 08, 2004 4:01 pm Post subject: (No 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 |
|
|
|
|
![](images/spacer.gif) |
|