java print a triangle

夙愿已清 提交于 2019-12-02 13:02:40

You have length += sideLength. This will keep adding the sideLength input to the length variable for each cycle of the while loop. What you probably want instead is just length = sideLength.

To make it print out your first prompt again on each iteration, simply put your System.out.print("State the length of the two sides (finish with -1): "); call inside your while loop. (It needs to come before sideLength = in.nextDouble(); as well so that the prompt is displayed before input is entered.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!