Hello! I have to print patterns using '*' and I am at a lose how to get these patterns printed!
I figured out the first one,
*
**
***
****
*****
******
*******
********
*********
**********
and now i have to do it upside down:
**********
*********
********
*******
******
*****
****
***
**
*
and backwards:
**********
*********
********
*******
******
*****
****
***
**
*
and
*
**
***
****
*****
******
*******
********
*********
**********
this is the code i have for the first one:
for (int i =0; i < 10; i++)
{
for (int j=0; j < i+1; j++)
{
System.out.print('*');
}
System.out.println();
}
and I figured if I just changed the numbers around and made i go from 10 to zero it would print out but it is not working. any help??? please!!
Thanks!
wouldnt you have to swap the loops around too? or maybe the sign from +->- or both. Havent tested just thinking logically now
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
actually, yes. but you also have to change the +'s to -'s, and < to >.
can you show the changed code you tried?
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
for(int k = 10; k > 0; k--){
for(int l=10; l > k; l--){
System.out.print('*');
}
System.out.println();
}
however this gives me exactly what I get in part a.
where is the -1 you had going in the original algorithm ?
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
you don't have to completely turn around the inner for loop.
and, in that for loop, you don't need to compare it to '10' but to the value of 'k'
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
the backward ones are just those two you already have printed right after each other.
you already have the code, just make sure its re-usable
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
I got part c but it is not aligned correctly....
how is it not aligned? can you show the algorithm?
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
part c? what is part c?
in this backwards you have to decide what to print
at first: the number of spaces, then the number of *'s
and this for each line
find a pattern to print this shape, and write the code for it
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
how is it not aligned? can you show the algorithm?
I thought of asking that too, but in this thread, his backwards is different from in the other thread :)
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433