zoukankan      html  css  js  c++  java
  • 用星星画菱形--Java

    用星星画菱形

    public class Hello{
        public static void main(String[] args) {
            char star = 'u2605';
            System.out.println("Hello " + star + " World!");
    
            // output a diamond shape with stars
            int temp1 = 0, temp2 = 0;
            for(int i=1; i<=4; ++i){
                temp1 = 4-i;
                temp2 = 2*(i-1)+1;
                while(temp1 > 0){
                    System.out.print("  "); // one star char width = two spacing
                    temp1--;
                }
                while(temp2 > 0){
                    System.out.print(star);
                    temp2--;
                }
                System.out.println();
            }
    
            for(int j=1; j<=3; ++j){
                temp1 = j;
                temp2 = 2*(3-j)+1;
                while(temp1 > 0){
                    System.out.print("  ");
                    temp1--;
                }
                while(temp2 > 0){
                    System.out.print(star);
                    temp2--;
                }
                System.out.println();
            }
        }
    }

    星星是个符号,其宽度有两个空格大小,utf-8编码为:u2605, 代码输出结果为:

    完!

  • 相关阅读:
    表单
    超链接
    图像
    表格
    排列清单控制标
    HTML基本结构
    如何快速查看网页源代码
    TOR的使用
    google搜索新姿势
    [NOIP2017]列队
  • 原文地址:https://www.cnblogs.com/mjk961/p/8998709.html
Copyright © 2011-2022 走看看