I need to do this:
***
***
***
**
*
and I have this code:
for(intI=0; i5; I )
{
for(intj=5; ji; j----)
{
}
which outputs this:
***
***
***
**
*
icantfigureouthowtoimplementthespaces.anyhelpappreciated。
解决方案
youneedtousetwofor-loops 3360 oneforthenumberofspacesandoneforthenumberof * :
for(intI=0; i 5; I ) {
for(intj=0; j i; j ) {
}
for(intj=I; j 5; j ) {
}
}
Java 8解决方案:
intstream.range (0,5 ).foreach ) I-{
Intstream.range(0,I ).Foreach ) j-system.out.print ) '');
Intstream.range(I,5 ).Foreach ) j-system.out.print('* ' );
);