zoukankan      html  css  js  c++  java
  • java打印实心10*10正方形, 空心10*10正方形

     1 public class PrintSquare {
     2 
     3     public static void main(String[] args) {
     4         printSolidSquare(10);
     5         System.out.println("==我是一条分割线==");
     6         printHollowSquare(10);
     7     }
     8 
     9     // 打印空心正方形
    10     private static void printHollowSquare(int n) {
    11         for (int i = 1; i <= n; i++) {
    12             for (int j = 1; j <= n; j++) {
    13                 if (i == 1 || i == n || j == 1 || j == n) {
    14                     System.out.print("* ");// 这里有一个空格
    15                 } else {
    16                     System.out.print("  ");// 这里有两个空格
    17                 }
    18             }
    19             System.out.println();
    20         }
    21     }
    22 
    23     // 打印实心正方形
    24     private static void printSolidSquare(int n) {
    25         for (int i = 1; i <= n; i++) {
    26             for (int j = 1; j <= n; j++) {
    27                 System.out.print("* ");// 这里有一个空格
    28             }
    29             System.out.println();
    30         }
    31     }
    32 
    33 }

     咱们来看看效果(不多说,上图):

    感觉效果还是不错的,但是就是不知道为什么我把星号(*)换成其他字符(比如❤)就不行了,>﹏<

  • 相关阅读:
    各种
    shell
    搭建个人信息平台
    基本tomcat+nginx
    vi编辑的使用
    linux权限管理
    Java观察者模式
    Flume+Kafka+Sparkstreaming日志分析
    科学计算与数学建模
    推荐系统起手式-几种简单推荐模型(基于内容的推荐)
  • 原文地址:https://www.cnblogs.com/zxfei/p/10702624.html
Copyright © 2011-2022 走看看