入学基础班学会的打印出菱形的代码,总感觉有地方多余,菜鸟刚入门,请大神指点下改进的地方,谢谢了!!!
class PrintGrapg1
{
public static void main(String[] args)
{
for (int x=1 ; x<=4 ; x++ )
{
for (int y=x; y<=4 ; y++ )
{
System.out.print("-");
}
for (int z=1 ; z<=x ; z++)
{
System.out.print("*"+" ");
}
System.out.println();
}
for (int x=2 ; x<=4 ; x++ )
{
for (int y=2; y<=x+1 ; y++ )
{
System.out.print("-");
}
for (int z=x ; z<=4 ; z++)
{
System.out.print("*"+" ");
}
System.out.println();
}
}
} |
|