run in this way,   no why,   only for you heart
CSDN博客(点击进入) CSDN
51CTO(点击进入) 51CTO

等腰三角形的打印

打印出一个等腰三角形。
思路很容易:双重for循环处理。
难点在于如何控制等腰,让图形像个金字塔,可以想象一个矩形挖成等腰三角形


package com.math.forth;

/***
 * 打印出一个等腰三角形。 思路很容易:双重for循环处理。 
 * 难点在于如何控制等腰,让图形像个金字塔
 * 
 * @author wql
 *
 */
public class Math12 {

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

    public static void method() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 9; j >= 1; j--) {
                if (j <= i) {
                    System.out.print("* ");
                } else
                    System.out.print(" ");
            }
            System.out.println();// 换行
        }
    }

    public static void method2() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (i < 10 - j) {
                    System.out.print(" ");
                } else
                    System.out.print("* ");
            }
            System.out.println();// 换行
        }

    }
}

这里写图片描述

posted @ 2017-10-24 22:14  _小龙人  阅读(168)  评论(0编辑  收藏  举报