zoukankan      html  css  js  c++  java
  • 等腰三角形的打印

    打印出一个等腰三角形。
    思路很容易:双重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();// 换行
            }
    
        }
    }
    

    这里写图片描述

  • 相关阅读:
    币值转换
    抓老鼠啊~亏了还是赚了?
    第十二周作业
    第十一周作业
    第十周作业
    第九周作业
    第八周作业
    第七周作业
    第五周实验报告和总结
    第四次实验报告及总结
  • 原文地址:https://www.cnblogs.com/wangqilong/p/8279768.html
Copyright © 2011-2022 走看看