日期:2014-05-20 浏览次数:20722 次
public static void main(String[] args)
{
System.out.print("请输入行数:");
Scanner input = new Scanner(System.in);
int rows = input.nextInt();
while (rows % 2 == 0)
{
System.out.print("请输入一个单数:");
rows = input.nextInt();
}
int n = (rows + 1) / 2;
System.out.println(n);
for (int i = 0; i <= n-1; i++)
{
for (int j = 0; j <= i; j++)
{
System.out.print(" ");
}
for (int k = 1; k <= rows - 2 * i; k++)
{
System.out.print("*");
}
System.out.print(" \n");
}
for (int i = 1; i < n; i++)
{
for (int j = 1; j <= n - i; j++)
{
System.out.print(" ");
}
for (int k = 1; k <= 2 * i + 1; k++)
{
System.out.print("*");
}
System.out.print("\n");
}
}