用Java編寫小程序打印“金字塔”
package demo1;
public class Demo {
public static void main(String[] args)
{
int a=4;
for(int i=1;i<=a;i++)
{
for(int k=1;k<=a-i;k++)
{
System.out.print(" ");
}
for(int j=1;j<=(i-1)*2+1;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}