>> hhm..
>> Okay.. This is what I have so far..
[quoted text clipped - 50 lines]
>
> - Oliver
hi..
I think I'm almost there..
It's getting rather frustrating and it feels like I hit another brick
wall..
public class Star
{
public static void main( String args[] )
{
int size = 9;
int insize = size;
// Start inverted triangle
for( int i = 0 ; i<=size ; i++ )
{
for( int k = 0 ; k<=i ; k++ )
{
System.out.print(".") ;// first print space equal to i
}
for ( int j=0 ; j <= insize ; j++ )
{
System.out.print("* ") ;// print star space
}
insize = insize -1 ;
System.out.println();
}
// end inverted triangle
// start upright triangle
int line = 1 ;
for( int i = size ; i >= 1 ; i-- )
{
for( int k = 1 ; k <= i ; k++ )
{
System.out.print(".") ;
}
for( int j = 0 ; j <= line ; j++ )
{
System.out.print("* ");
}
line++ ;
System.out.println() ;
}
// end upright triangle
}
}
the pattern I'm getting is as follows
10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10
I'm looking for
9 7 5 3 1 3 5 7 9
I hope there's SOMETHING i can do to my code.. And not have to start
again..
jagonzal@gmail.com - 22 Mar 2006 23:04 GMT
> the pattern I'm getting is as follows
>
[quoted text clipped - 5 lines]
> I hope there's SOMETHING i can do to my code.. And not have to start
> again..
Try moving your indexes by twos instead of ones? (for example, use
"k+=2" instead of "++k")
Oliver Wong - 22 Mar 2006 23:07 GMT
> hi..
>
[quoted text clipped - 57 lines]
> I hope there's SOMETHING i can do to my code.. And not have to start
> again..
You're printing a star, then a space ("* "), my understanding is that
this is NOT what you want, but given the comments present in the source
code, it looks like you were doing this intentionally.
Anyway, you are almost done. If you change a single character, it will
work.
- Oliver
Roedy Green - 23 Mar 2006 02:09 GMT
>for( int k = 1 ; k <= i ; k++ )
> {
[quoted text clipped - 4 lines]
> System.out.print("* ");
> }
another sort of trick you can use for this sort of problem looks like
this
for( int i = 1 ; i <= n ; i++ )
{
System.out.print( ( boolean expression of i ) ? '*' : ' ' );
}
I leave it to you to figure out what the expression looks like.
hint mathmaticians like to write things like this
if ( a _<_b _<_ c )
which in Java comes out
if ( a <= b && b <= c )

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Tom Leylan - 23 Mar 2006 03:35 GMT
Hi Ivan:
You are getting closer. I think you've recognized a sequence but I don't
think you're seeing the pattern. It's a formula where the star length
decreases by two at each step until there is one star at which point the
star length increases by two. At the same time the blank length adjusts by
the same value in the opposite direction. Interestingly you don't have to
keep track of the number of blanks only the stars because you can calculate
blanks at any time by subtracting stars from total rows.
I originally wrote my version as two procedures in a dummy class but I've
subsequently rewrote it as a static class which can be used as follows:
Stars.ProcessX( "*", ".", 5 );
Stars.ProcessX( "X", ".", 8 );
It even self-corrects in the second example. I check to see if the number
of rows is odd and if it isn't I add one to it.
One other idea (I know you're learning this) but you want to encapsulate
whatever you can to offer reuse. You are making a lot of calls to
System.out.print() for instance. It doesn't matter how many call you make
but that they are scattered throughout the code and that make it difficult
to change if the next thing you want to do is draw graphics instead. I put
all mine in a private method named StarsOut(). It is using
System.out.print() but the mechanism for all output is there and there
alone.
Seemingly I could add other processes to my Stars class that could output
other shapes as well. You would end up having to rewrite Main().
One step at a time though :-)
> hi..
>
> I think I'm almost there..
>
> It's getting rather frustrating and it feels like I hit another brick
> wall..
<code snipped>
> the pattern I'm getting is as follows
>
[quoted text clipped - 5 lines]
> I hope there's SOMETHING i can do to my code.. And not have to start
> again..