ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

For循环语句绘制图形

2022-06-06 09:02:04  阅读:218  来源: 互联网

标签:语句 int System -- print 图形 绘制 public out


 1 package com.luckylu.structure;
 2 
 3 public class ForLessson06 {
 4     public static void main(String[] args) {
 5         // 三角形
 6             for (int y = 1; y<=5; y++) {
 7                 for (int x1 =10; x1>1; x1--) {
 8                     if (x1>y) {
 9                         System.out.print(" ");
10                     }else {
11                         System.out.print("*");
12                     }
13                 }
14                 for (int x2 =1;x2<=y;x2++){
15                     System.out.print("*");
16                 }
17                 System.out.println();
18             }
19         System.out.println("======================");
20 //        三角形
21         for (int i = 1; i <= 5; i++) {
22             // 画左边  空格三角
23             for (int j = 10; j>=i; j--) {
24                 System.out.print(" ");
25             }
26             //  画  星中间三角
27             for (int j= 1 ; j<=i ;j++){
28                 System.out.print("*");
29             }
30             // 画  右边三角
31             for (int j =1 ; j<=i ; j++){
32                 System.out.print("*");
33             }
34             System.out.println();
35         }
36         System.out.println("======================");
37 //   5*5正方形
38         for (int i = 1; i <= 5 ; i++) {
39             // 向右移动距离 10个空格位
40             for (int j = 1; j <=10 ; j++) {
41                 System.out.print(" ");
42             }
43             //  绘制5个形
44             for (int j = 1; j <=5 ; j++) {
45                 System.out.print("*");
46             }
47             System.out.println();
48         }
49         System.out.println("======================");
50 //        菱形
51         for (int i = 1; i <=5 ; i++) {
52 //            绘制空格 倒三角
53             for (int j = 5; j>=i ; j-- ) {
54                 System.out.print(" ");
55             }
56 //            绘制10个星的菱形
57             for (int j = 1; j <=10  ; j++) {
58                     System.out.print("*");
59             }
60             System.out.println();
61         }
62         System.out.println("======================");
63 //        菱形
64         for (int i = 1; i <= 5 ; i++) {
65 //            正三角空格
66             for (int j = 1; j<=i ; j++) {
67                 System.out.print(" ");
68             }
69             for (int j = 1; j <=10 ; j++) {
70                 System.out.print("*");
71             }
72             System.out.println();
73         }
74     }
75 }

输出结果

         *
        ***
       *****
      *******
     *********
======================
          **
         ****
        ******
       ********
      **********
======================
          *****
          *****
          *****
          *****
          *****
======================
     **********
    **********
   **********
  **********
 **********
======================
 **********
  **********
   **********
    **********
     **********

 

标签:语句,int,System,--,print,图形,绘制,public,out
来源: https://www.cnblogs.com/luckylu/p/16346981.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有