首页 > 编程知识 正文

java打印三角形如何理解,java打印三角形原理

时间:2023-05-04 20:07:15 阅读:153361 作者:4195

打算编写需要用户输入三角形的时间和方向等的程序。 我的问题是,在运行程序后,我会继续在程序中添加更多的数字。

statethelengthofthetwosides (finish with-1 ) : 5) 5

shouldthetrianglefacedown(0) or up(1)1) : 1

*

**

***

***

***

2

shouldthetrianglefacedown(0) or up(1)1) : 1

*

**

***

***

***

******

* * * * * * * *

import java.util.Scanner;

public class Triangel {

publicstaticvoidmain (stringyydbdargs ) {

sannerin=newscanner(system.in;

//initieringsvariablerfrtriangelsida。

双长度=0;

double sideLength=0;

//This part will ask for user input

.打印(statethelengthofthetwosides ) Finishwith-1 ) : );

wile(sideLength!=-1({

//Input。

sideLength=in.nextDouble (;

if (滑动长度!=-1({

//inputwillbesavedinvariablelength。

length =sideLength;

//thispartwillasktheusertostatewhetherthetriangleis

//up or down .

.打印(shouldthetrianglefacedown )0) or up(1)1) : );

String direction=in.next (;

//ifthevariablesdirectionisequalto (1) this part will

//run。

if(direction.equals('1) ) )

for(intI=1; I=() (int ) )长度); I ) {

for(intj=1; j=i; j ) {

}

}

}

//ifdirectionequalsto(0)。

else {

for(intI=1; I=() (int ) )长度); I ) {

for(intj=) (int ) ) length ); j=1; j----) {

if(j=I ) ) )

}

}

}

}

}

}

}

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