zoukankan      html  css  js  c++  java
  • java--输出一个菱形

    java源代码:

    package studying;
    
    /*
     * Print Diamond
     */
    
    public class PrintDiamond {
    
        public static void main(String[] args) {
    
            //Upper part
            for(int m = 1; m <= 10; m++) {
                
                //Output Spaces
                for(int n = 9; n >= m; n--) {
                    System.out.print(" ");
                }
                
                //Output * Upper Left
                for(int n = 1; n <= m; n++) {
                    System.out.print("*");
                }
                
                //Output * Upper Right
                for(int n = 1; n < m; n++) {
                    System.out.print("*");
                }
                System.out.println();
            }
            
            
            //Second half
            for(int m = 1; m <= 9; m++) {
                
                //output spaces
                for(int n = 1; n<=m; n++) {
                    System.out.print(" ");
                }
                
                //Output * Lower left
                for(int n = 9; n >= m; n--) {
                    System.out.print("*");
                }
                
                //Output * Lower right
                for(int n = 9; n > m; n--) {
                    System.out.print("*");
                }
                System.out.println();
            }
    
        }
    
    }

    结果展示:

  • 相关阅读:
    hadoop基础
    数据库基础知识
    sqoop基础
    大数据之常用linux常用命令
    zooKeeper基础
    impala基础
    Hbase基础
    Commitlint 提交规范类型
    理解JS闭包
    JS函数作用域及作用域链理解
  • 原文地址:https://www.cnblogs.com/superdrew/p/8067530.html
Copyright © 2011-2022 走看看