对于我的任务,我应该使用方法绘制带星号的钻石。如何绘制带星号的钻石
我想通了,如何让第一部分(居中三角形)
我不能代表上帝的爱看着办吧。我花了4个多小时尝试不同的事情,我想如何制作一个颠倒的三角形,但钻石不工作。
这就是我的第一部分。有人可以告诉我如何翻转它,以便在与颠倒的版本一起使用时形成钻石?
{
int rows = userInputHeight;
int starCount = 1;
int spaceCount = rows - 1;
for(int rowCount = 1; rowCount <= rows; rowCount++)
{
for(int numb = 1; numb <= spaceCount; numb++)
{
System.out.print(" ");
}
for(int count = 1; count <=starCount; count++ )
{
System.out.print("*");
}
System.out.println();
starCount += 2;
spaceCount--;
}
}
这是它显示(UserInputHeight = 10):
*
***
*****
*******
*********
***********
这就是我想要的(UserInputHeight = 19):
*
***
*****
*******
*********
***********
***********
*********
*******
*****
***
*
这是我到目前为止第二部分:
int rows = userInputHeight;
int starCount = rows*2;
int spaceCount =userInputPadding;
if (userInputHeight % 2 == 0)
{
userInputHeight+=1;
}
for (int rowCount = rows; rowCount >= 1; rowCount --)
{
for (int i = 0; i <= (rows - rowCount)+ spaceCount; i++)
{
System.out.print(' ');
}
for (int i = 1; i < starCount; i++)
{
System.out.print('*');
}
System.out.println();
starCount -=2;
}
}
请帮忙。
javascript在什么地方出现? – mplungjan
您最后一次打印的方法是什么? –