我需要帮助解决以下问题.该程序有三个输出:一个三角形和两个圣诞树.我已成功打印三角形,但我无法弄清楚如何使我的树工作.以下是练习40的链接:https://materiaalit.github.io/2013-oo-programming/part1/week-2/
请注意,这不是我的小工作.我正在学习如何在家里自己编码.
这是代码:
public static void xmasTree(int height) {
for (int i = 1; i <= height; i++ ) {
printWhitespaces(height - 1);
printStars( i );
}
for( int j = 2; j <= height; j++ ){
printWhitespaces ( height - j );
printStars ( j - 1 );
}
}
Run Code Online (Sandbox Code Playgroud)
这必须是最终输出:
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
***
***
Run Code Online (Sandbox Code Playgroud)
但我明白了:
*
**
***
****
*****
******
*******
********
*********
**********
*
** …Run Code Online (Sandbox Code Playgroud) java ×1