import java.util.Scanner;
public class Ideone
{
public static void main(String[] args)
{
int reader;
Scanner kBoard = new Scanner(System.in);
do
{
System.out.println("Insert a number of rows: ");
reader = kBoard.nextInt();
printDiamond(reader);
}while(reader != 0);
}
public static void printWORD(int n)
{
if(n >= 1)
{
System.out.print("SAMPLE");
printWORD(n - 1);
}
}
public static void printTopTriangle(int rows)
{
int x = 1;
for(int j = (rows - 1); j >= 0; j--,x +=2)
{
printSpaces(j);
printWORD(x);
System.out.print("\n");
}
}
public static void printSpaces(int n)
{
if(n >= 1)
{
System.out.print(" ");
printSpaces(n - 1);
}
}
public static void printBottomTriangle(int rows, int startSpaces)
{
int x = 1 + (2*(rows - 1));
for(int j = startSpaces; j <= (rows) && x > 0; j++,x -=2)
{
printSpaces(j);
printWORD(x);
System.out.print("\n");
}
}
public static void printBottomTriangle(int rows)
{
int x = 1 + (2*(rows - 1));
for(int j = 0; j <= (rows - 1) && x > 0; j++,x -=2)
{
printSpaces(j);
printWORD(x);
System.out.print("\n");
}
}
public static void printDiamond(int rows)
{
printTopTriangle((int)rows/2 + 1);
printBottomTriangle((int)rows/2, 1);
}
}
我的程序应该显示由单词“SAMPLE”组成的菱形。但是当我运行它时,它会显示一个太空船的形状。如何修复此错误,以便打印带有“SAMPLE”字样的完美钻石?