http://www.jianshu.com/p/6ae999d2d6ba/
package com.company;
public class Main {
public static void main(String[] args) {
int n=7,i,j,k;
for(i=1;i<=(n+1/2);i++)
{
for(j=1;j<=(n-(i-1)*2-1)/2+1;j++)
if(i==1)
{
for(k=1;k<=(n-1)/2;k++)
{
System.out.print("*");
}
break;
}else
System.out.print("*");
for(j=1;j<=(i-1)*2-1;j++)
System.out.print(" ");
for(j=1;j<=(n-(i-1)*2-1)/2+1;j++)
System.out.print("*");
if(i<=(n-1)/2)
System.out.print("\n");
}
System.out.print("\n");
for(i=n/2;i>=1;i--)
{
for(j=1;j<=(n-(i-1)*2-1)/2+1;j++)
if(i==1)
{
for(k=1;k<=(n-1)/2;k++)
{
System.out.print("*");
}
break;
}else
System.out.print("*");
for(j=1;j<=(i-1)*2-1;j++)
System.out.print(" ");
for(j=1;j<=(n-(i-1)*2-1)/2+1;j++)
System.out.print("*");
System.out.print("\n");
}
}
}