最近流行的心型代码呀~~
class Heart
{
public static void main(String[] args)
{
//上三行
for (int i = 0;i <= 2;i++ )
{
for (int j = 0;j <= (5 - 2 * i) + 25;j++)
{
System.out.print(" ");
}
if (i == 0)
{
for (int k = 0;k <= 7;k++)
{
System.out.print("*");
}
for (int j = 0;j <= 6;j++)
{
System.out.print(" ");
}
for (int k = 0;k <= 7;k++)
{
System.out.print("*");
}
System.out.println();
}else if (i == 1)
{
for (int k = 0;k <= 11;k++)
{
System.out.print("*");
}
for (int j = 0;j < 3;j++)
{
System.out.print(" ");
}
for (int k = 0;k <= 11;k++)
{
System.out.print("*");
}
System.out.println();
}else
{
for (int k = 0;k <= 14;k++)
{
System.out.print("*");
}
for (int j = 0;j < 1;j++)
{
System.out.print(" ");
}
for (int k = 0;k <= 14;k++)
{
System.out.print("*");
}
System.out.println();
}
}
//4-6行
for (int i = 0;i <= 2;i++)
{
if (i == 0 || i == 1)
{
for (int k = 0;k <=25;k++)
{
System.out.print(" ");
}
for (int j = 0;j <= 32;j++)
{
System.out.print("*");
}
}else
{
for (int k = 0;k <= i + 24;k++)
{
System.out.print(" ");
}
for (int x = 0;x <= 32 - i;x++)
{
System.out.print("*");
}
}
System.out.println();
}
//下半段
for (int i = 0;i <= 7;i++ )
{
for (int j = 0;j <= (2 * i + 1) + 26;j++)
{
System.out.print(" ");
}
for (int k = 0;k <= 28 - 4 * i;k++)
{
System.out.print("*");
}
System.out.println();
}
}
}
运行结果:
******** ********
************ ************
*************** ***************
*********************************
*********************************
*******************************
*****************************
*************************
*********************
*****************
*************
*********
*****
*