Java 如何画带星号的钻石
对于我的作业,我应该用方法画一个带星号的菱形 我想出了如何制作第一部分(居中三角形) 看在上帝的份上,我想不出来。我花了4个多小时尝试不同的东西,我想出了如何制作一个倒三角形,但钻石不起作用 这是我第一部分的内容。有人能告诉我如何翻转它,使它在与倒置版本一起使用时形成钻石吗Java 如何画带星号的钻石,java,geometry,draw,Java,Geometry,Draw,对于我的作业,我应该用方法画一个带星号的菱形 我想出了如何制作第一部分(居中三角形) 看在上帝的份上,我想不出来。我花了4个多小时尝试不同的东西,我想出了如何制作一个倒三角形,但钻石不起作用 这是我第一部分的内容。有人能告诉我如何翻转它,使它在与倒置版本一起使用时形成钻石吗 { int rows = userInputHeight; int starCount = 1; int spaceCount = rows - 1; for( int rowCount
{
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=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;
}
}
int starCount=行*2;
int spaceCount=userInputPadding;
如果(用户权限%2==0)
{
userinputhweight+=1;
}
对于(int rowCount=rows;rowCount>=1;rowCount--)
{
对于(int i=0;i请尝试以下方法:
public static void drawDiamond(int height) {
if (height % 2 == 0) throw new AssertionError("Height should be an odd number!");
height = (height + 1) / 2;
drawTop(height);
drawBot(height - 1);
}
public static void drawTop(int height) {
int rows = height;
int starCount = 1;
int spaceCount = rows - 1;
for (int rowCount = 1; rowCount <= rows; rowCount++) {
for (int i = 0; i < spaceCount; i++) {
System.out.print(" ");
}
for (int i = 0; i < starCount; i++) {
System.out.print("*");
}
starCount += 2;
spaceCount--;
System.out.println();
}
}
public static void drawBot(int height) {
int rows = height;
int starCount = 2 * (rows - 1) + 1;
int spaceCount = 1;
for (int rowCount = 1; rowCount <= rows; rowCount++) {
for (int i = 0; i < spaceCount; i++) {
System.out.print(" ");
}
for (int i = 0; i < starCount; i++) {
System.out.print("*");
}
starCount -= 2;
spaceCount++;
System.out.println();
}
}
public静态无效绘制菱形(整数高度){
如果(高度%2==0)抛出新的断言错误(“高度应为奇数!”);
高度=(高度+1)/2;
吸顶(高度);
drawBot(高度-1);
}
公共静态中空抽拉台面(内部高度){
int行=高度;
int starCount=1;
int spaceCount=行数-1;
对于(int rowCount=1;rowCount,这里是另一个角度
注:从中线到最高点的高度
public static void DrawDiamond(int height)
{
DiamondTop(height);
DiamondBottom(height);
}
public static void DiamondTop(int height)
{
for (int row = 1; row <= height; row++)
{
for (int padding = height - row; padding > 0; padding--)
{
System.out.print(" ");
}
for (int numberOfAsterisks = (row * 2) - 1; numberOfAsterisks > 0; numberOfAsterisks--)
{
System.out.print("*");
}
System.out.println();
}
}
public static void DiamondBottom(int height)
{
for (int row = height - 1; row > 0; row--)
{
for (int padding = row; padding < height; padding++)
{
System.out.print(" ");
}
for (int numberOfAsterisks = (row * 2) - 1; numberOfAsterisks > 0; numberOfAsterisks--)
{
System.out.print("*");
}
System.out.println();
}
}
public静态无效绘制菱形(整数高度)
{
钻石顶(高度);
钻石底(高);
}
公共静态空隙钻石顶(内部高度)
{
对于(int行=1;行0;填充--)
{
系统输出打印(“”);
}
对于(int numberOfAsterisks=(第*2行)-1;numberOfAsterisks>0;numberOfAsterisks--)
{
系统输出打印(“*”);
}
System.out.println();
}
}
公共静态空隙菱形底部(内部高度)
{
对于(int行=高度-1;行>0;行--)
{
对于(int padding=行;padding<高度;padding++)
{
系统输出打印(“”);
}
对于(int numberOfAsterisks=(第*2行)-1;numberOfAsterisks>0;numberOfAsterisks--)
{
系统输出打印(“*”);
}
System.out.println();
}
}
javascript是从哪里来的?您最后的打印方法是什么?
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;
}
}
public static void drawDiamond(int height) {
if (height % 2 == 0) throw new AssertionError("Height should be an odd number!");
height = (height + 1) / 2;
drawTop(height);
drawBot(height - 1);
}
public static void drawTop(int height) {
int rows = height;
int starCount = 1;
int spaceCount = rows - 1;
for (int rowCount = 1; rowCount <= rows; rowCount++) {
for (int i = 0; i < spaceCount; i++) {
System.out.print(" ");
}
for (int i = 0; i < starCount; i++) {
System.out.print("*");
}
starCount += 2;
spaceCount--;
System.out.println();
}
}
public static void drawBot(int height) {
int rows = height;
int starCount = 2 * (rows - 1) + 1;
int spaceCount = 1;
for (int rowCount = 1; rowCount <= rows; rowCount++) {
for (int i = 0; i < spaceCount; i++) {
System.out.print(" ");
}
for (int i = 0; i < starCount; i++) {
System.out.print("*");
}
starCount -= 2;
spaceCount++;
System.out.println();
}
}
public static void DrawDiamond(int height)
{
DiamondTop(height);
DiamondBottom(height);
}
public static void DiamondTop(int height)
{
for (int row = 1; row <= height; row++)
{
for (int padding = height - row; padding > 0; padding--)
{
System.out.print(" ");
}
for (int numberOfAsterisks = (row * 2) - 1; numberOfAsterisks > 0; numberOfAsterisks--)
{
System.out.print("*");
}
System.out.println();
}
}
public static void DiamondBottom(int height)
{
for (int row = height - 1; row > 0; row--)
{
for (int padding = row; padding < height; padding++)
{
System.out.print(" ");
}
for (int numberOfAsterisks = (row * 2) - 1; numberOfAsterisks > 0; numberOfAsterisks--)
{
System.out.print("*");
}
System.out.println();
}
}