• Java语言输出菱形图型


    package fuxi;

    public class Diamond {

        public static void main(String[] args) {
            printHollowRhombus(4);

        }

        private static void printHollowRhombus(int size) {
            if (size%2 == 0) {
                size++;
            }
            for(int i = 0; i<size/2+1; i++){
                for (int j=size/2+1; j>i+1; j-- ) {
                    System.out.print(" "); //输出左上角的空白
                    
                }
                for (int j=0; j<2*i+1; j++) {
                    if (j==0 || j==2*i) {
                        System.out.print("*"); //输出上半部的边缘
                    }else{
                        System.out.print(" "); //输出菱形上半部的空心
                        
                    }
                }
                System.out.println("");// 换行
            }
            for (int i=size/2+1; i<size; i++) {
                for (int j=0; j<i-size/2; j++) {
                    System.out.print(" ");//输出左下角的空白
                }
                for (int j=0; j<2*size-1 - 2*i; j++ ) {
                    if (j==0 || j==2*(size-i-1)) {
                        System.out.print("*"); //输出下半部的边缘
                    }else{
                        System.out.print(" ");//输出菱形下半部的空心
                        
                    }
                }
                System.out.println("");// 换行
            }
            
        }

    }

  • 相关阅读:
    UVA
    UVA
    UVA
    UVA
    NLP介绍
    新建Springboot项目
    添加ssh密钥
    git 错误合集
    Git入门操作
    Hadoop MapReduce
  • 原文地址:https://www.cnblogs.com/changankaifazhe/p/10019079.html
Copyright © 2020-2023  润新知