/*
* 定义方法,使用嵌套for循环画出如下图形
矩形,空心矩形,正立直角三角形,倒立直角三角形,等腰三角形
*/
class Task
{
public static void main(String[] args)
{
for (int i=1;i<=6 ;i++ )//矩形
{
for (int j=1;j<=8 ;j++ )
{
System.out.print("* ");
}
System.out.println();
}
System.out.println("=====================");
for (int i=1;i<=6 ;i++ ) //空心矩形
{ for (int j=1;j<=8 ;j++ )
{
if (i==1||i==6||j==1||j==8)
{
System.out.print("* ");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("=====================");
for (int i=1;i<=6 ;i++ )//正立直角三角形
{
for (int j=1;j<=i ;j++ )
{
System.out.print("* ");
}
System.out.println();
}
System.out.println("======================");
for (int i=1;i<=6 ;i++ )//倒立直角三角
{
for (int j=i;j<=6 ;j++ )
{
System.out.print("* ");
}
System.out.println();
}
System.out.println("=======================");
for (int i=1;i<=6 ;i++ )//等腰三角形
{
for (int z=i;z<=6 ;z++ )
{
System.out.print(" ");
}
for (int j=1; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
System.out.println("========================");
for (int i=1;i<=7 ;i++ )//等腰三角形
{
for (int j=1;j<=7-i ;j++ )
{
System.out.print(" ");
}
for (int k=1; k<=2*i-1;k++ )
{
System.out.print("*");
}
System.out.println();
}
System.out.println("==========================");
for (int i=1;i<=7 ;i++ )//空心三角形
{
//内循环一控制空格的输出
for (int j=1;j<=7-i ;j++ )
{
System.out.print(" ");
}
//内循环二控制*的输出
for (int k=1; k<=2*i-1;k++ )
{
//判断是本行的第一个,最后一个和最后一行打印
if(k==1||k==2*i-1||i==7)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("==========================");
}
}
|
|