zoukankan      html  css  js  c++  java
  • 用Java在控制台画一个菱形

    二话不说,直接上代码:

    package javaapplication2;
     
    /**
     *
     * @author CodeMonkey
     */
    public class JavaApplication2 {
     
        /**
         * @param jid the command line arguments
         */
           public static void main(String [] args)
        {
            JavaApplication2 Test = new JavaApplication2();
            if (args.length==0)
                Test.print(22);
            else
                Test.print(Integer.parseInt(args[0]));
        }
     
       public void print(int x) {
         for(int k = x >>> 1, i = -k; i <= k; i++) {
             System.out.print("			");
             for(int j = -k, m = k - Math.abs(i); j <= m; j++) {
                 System.out.print(Math.abs(j) + Math.abs(i) == k || i * j == 0 ? '*' : ' ');
             }
             System.out.println();
         }
    }
    }
  • 相关阅读:
    js原型杂谈
    arguments.callee.caller
    $resource
    sql的四种匹配模式
    AMD规范
    module.ngdoc
    angularjs杂谈
    浏览器前缀
    css21规范学习
    <meta>标签
  • 原文地址:https://www.cnblogs.com/liuxgnu/p/3535455.html
Copyright © 2011-2022 走看看