码迷,mamicode.com
首页 > 编程语言 > 详细

Java经典编程题50道之十九

时间:2017-06-04 22:44:31      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:example   static   play   str   菱形   nbsp   bsp   打印   经典   

打印出如下图案(菱形)
        *
      ***
    ******
  ********
    ******
      ***
        *

public class Example19 {
    public static void main(String[] args) {
        display(5);
    }

    public static void display(int h) {
        for (int i = 0; i < (h + 1) / 2; i++) {
            for (int j = 0; j < h / 2 - i; j++) {
                System.out.print(" ");
            }
            for (int k = 1; k < (i + 1) * 2; k++) {
                System.out.print("*");
            }
            System.out.println();
        }
        for (int i = 1; i <= h / 2; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(" ");
            }
            for (int j = 0; j < h - 2 * i; j++) {
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Java经典编程题50道之十九

标签:example   static   play   str   菱形   nbsp   bsp   打印   经典   

原文地址:http://www.cnblogs.com/qubo520/p/6942089.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!