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