zoukankan      html  css  js  c++  java
  • 在Java中用for循环打印菱形

    package demo;
    
    import java.util.*;
    
    /**
    * 用循环打印菱形
    * @author Administrator
    * 
    */
    public class Rhomb {
      public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int row; // 菱形行数
        System.out.print("请输入菱形行数:");
        row = in.nextInt();
        while (row % 2 == 0) { // 判断菱形行数是否是奇数
          System.out.print("请输入奇数:");
          row = in.nextInt();
        }
        int size = (row + 1) / 2; 
        /**     * 上半部     */     for (int i = 1; i <= size; i++) {       for (int j = 1; j <= size - i; j++) {         System.out.print(" ");       }       for (int j = 1; j <= 2 * i - 1; j++){         System.out.print("*");       }       System.out.println();     }
        
    /**     * 下半部     */     for (int i = 1; i <= size - 1; i++){       for (int x = 1; x <= i; x++){         System.out.print(" ");       }       for (int y = i; y < row-i; y++){         System.out.print("*");       }       System.out.println();     }   } }
  • 相关阅读:
    Hadoop集群时间同步
    Hadoop学习笔记
    分布式系统搭建
    ubuntu主机名修改
    自定义MapReduce中数据类型
    MapReduce执行流程及程序编写
    YARN框架详解
    Maven下从HDFS文件系统读取文件内容
    Maven搭建Hadoop开发环境
    hdfs文件系统架构详解
  • 原文地址:https://www.cnblogs.com/GIRLANDBOYS/p/6700762.html
Copyright © 2011-2022 走看看