對於我的任務,我應該使用方法繪製帶星號的鑽石。如何繪製帶星號的鑽石
我想通了,如何讓第一部分(居中三角形)
我不能代表上帝的愛看着辦吧。我花了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
您最後一次打印的方法是什麼? –