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"이라는 단어가있는 완벽한 다이아몬드를 인쇄 할 수 있도록이 오류를 어떻게 수정합니까?프로그램 실행시 모양이 잘못됨
고마워의 길이입니다! 이제 완벽하게 작동합니다! –