zoukankan      html  css  js  c++  java
  • 19 打印菱形图案

    题目: 打印出如下图案(菱形)

         *
       ***
     *****
    *******
     *****
       ***
        *

     1     public class _019PrintDiamond {
     2 
     3     public static void main(String[] args) {
     4         printDiamond();
     5     }
     6 
     7     private static void printDiamond() {
     8         int hight = 7, width = 7;
     9         
    10         //打印上三角
    11         for(int i =0;i<(hight+1)/2;i++){
    12             //行循环
    13             for(int j =0;j<width/2-i;j++){
    14                 //循环图形中的空格数量
    15                 System.out.print(" ");
    16             }
    17             
    18             //列循环
    19             for (int s=1;s<(i+1)*2;s++) {
    20                 System.out.print('*');
    21             }
    22             System.out.println();
    23         }
    24         
    25         //打印下三角
    26         for(int i =1;i<=hight/2;i++){
    27             for(int j =1;j<=i;j++){
    28                 System.out.print(" ");
    29             }
    30             
    31             for (int s=1;s<=width-2*i;s++) {
    32                 System.out.print('*');
    33             }
    34             System.out.println();
    35         }
    36     }
    37 }
  • 相关阅读:
    c++:函数模板
    1084 外观数列
    1083 是否存在相等的差
    1082 射击比赛
    1081 检查密码
    1080 MOOC期终成绩
    1079 延迟的回文数
    1078 字符串压缩与解压
    1077 互评成绩计算
    1076 Wifi密码
  • 原文地址:https://www.cnblogs.com/liuyangfirst/p/6514639.html
Copyright © 2011-2022 走看看