My goal is to get this output when input is 3:
* *
* *
* *
*
* *
* *
* *
Here is my code:
public static void PrintX (int number) {
for (int i = 0; i <= (number * 2 + 1); i++)
{
for (int j = 0; j <= (number * 2 + 1); j++)
{
if (i == j)
{
System.out.print("*");
}
else if (i + j == (number * 2 + 2))
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
}
}
My output when input is 3 is like this and I'm not sure why there is the extra star at the top.
*
* *
* *
* *
*
* *
* *
* *
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…