首页 > 编程知识 正文

c语言倒直角三角形,javafor循环打印直角三角形

时间:2023-05-03 10:42:13 阅读:153360 作者:4531

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('* ' );

);

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。