日期:2014-05-20  浏览次数:20605 次

帮我正等腰三角挖空,一下想不起来
public class ccc {

public static void main(String[] args) {
a();
}

public static void a() {
System.out.println("打印正等腰三角");
int i, j;
for (i = 1; i <= 5; i++) {
for (j = 5; j > i; j--) {
System.out.print(" ");
}
for (j = 0; j < i * 2 - 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}

------解决方案--------------------
Java code


public class ccc
{
    
    public static void main(String[] args)
    {
        a();
    }
    
    public static void a()
    {
        System.out.println("打印正等腰三角");
        int i, j;
        for (i = 1; i <= 5; i++)
        {
            for (j = 5; j > i; j--)
            {
                System.out.print(" ");
            }
            for (j = 0; j < i * 2 - 1; j++)
            {
                if (j == 0 || j == (i * 2 - 2) || i == 5)
                {
                    System.out.print("*");
                }
                else {
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}