import javautilScanner;
public class test{
static void draw(int n)
{
int i,j;
for (i=1-(n>>1);i<=n;i++)
if (i>0)
{
for (j=0;j<i;j++) Systemoutprint(" ");
for (j=1;j<=2(n-i)+1;j++)
if (j==1||j==2(n-i)+1) Systemoutprint(" ");
else Systemoutprint(" ");
Systemoutprintln("\n");
}
else
if (i==0)
{
Systemoutprint(" ");
for (j=1;j<n;j++) Systemoutprint(" ");
Systemoutprint(" ");
for (j=1;j<n;j++) Systemoutprint(" ");
Systemoutprint(" \n");
}
else
{
for (j=i;j<0;j++) Systemoutprint(" ");
for (j=1;j<=n+2i+1;j++)
if (i==1-(n>>1)) Systemoutprint(" ");
else if (j==1||j==n+2i+1) Systemoutprint(" ");
else Systemoutprint(" ");
for (j=1;j<=-1-2i;j++) Systemoutprint(" ");
for (j=1;j<=n+2i+1;j++)
if (i==1-(n>>1)) Systemoutprint(" ");
else if (j==1||j==n+2i+1) Systemoutprint(" ");
else Systemoutprint(" ");
Systemoutprint("\n");
}
}
public static void main(String[] args) {
Systemoutprintln("Please input the size (n>=4):");
Scanner sc = new Scanner(Systemin);
int n = scnextInt();
draw(n);
}
}先说明这个不是我写的 是看了有人用C语言写的 就顺便改成了java 结果有点像爱心 还凑合着 你看看怎么样吧 哈
欢迎分享,转载请注明来源:表白网
评论列表(0条)