public class pyramid
{
public static void main(String[] args){
int i=1; // i 是层数
int j=1;//j是列数
int space=1; //是空格
for (i=1; i<=5;i++){
for (space=1; space <=(5-i);space++){
System.out.print (" ");
}
for(j=1;j<=(2*i-1);j++){
if(j==1||j==(2*i-1)||i==5){
System.out.print ("*");
}
else {
System.out.print (" ");
}
}
System.out.println (" ");
}
}
}
效果