我们平时都是使用的画图工具进行简单图形的绘制,今天我们使用java打印一些简单的图形
实现代码如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
package test;
/**
*
* @author hanzel
* @打印图形
*
*/
public class Array {
public static void main(String[] args) {
//打印长方形
int [] a = new int [ 10 ];
for ( int i= 0 ;i<a.length;i++){
for ( int j= 0 ;j<a.length;j++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//打印倒直角三角形
int [] b = new int [ 10 ];
for ( int i= 0 ;i<b.length;i++){
for ( int j= 0 ;j<b.length-i;j++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//另一种倒直角三角形
int [] e = new int [ 10 ];
for ( int i= 0 ;i<e.length;i++){
for ( int j= 0 ;j<i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m<e.length-i;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//打印出平行四边形
int [] c = new int [ 10 ];
for ( int i= 0 ;i<c.length;i++){
for ( int j= 0 ;j<i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m<c.length;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//另一种平行四边形
int [] h = new int [ 10 ];
for ( int i= 0 ;i<h.length;i++){
for ( int j= 0 ;j<h.length-i;j++){
System.out.print( " " );
}
for ( int m= 0 ; m<h.length;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//打印正直角三角形
int [] d = new int [ 10 ];
for ( int i= 0 ;i<d.length;i++){
for ( int j= 0 ;j<i;j++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//打印另一种正直角三角形
int [] f = new int [ 10 ];
for ( int i= 0 ;i<f.length;i++){
for ( int j= 0 ;j<f.length-i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m<i;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//打印出直角梯形
int [] g = new int [ 10 ];
for ( int i= 0 ;i<g.length;i++){
for ( int j= 0 ;j<g.length;j++){
System.out.print( "*" );
}
for ( int m= 0 ;m<i;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//等腰三角形
int [] k = new int [ 10 ];
for ( int i= 0 ;i<k.length;i++){
for ( int j= 0 ;j<k.length-i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m< 2 *(i+ 1 )- 1 ;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//另一种等腰三角形
int [] l = new int [ 10 ];
for ( int i= 0 ;i<l.length;i++){
for ( int j= 0 ;j<i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m< 2 *(l.length-i)- 1 ;m++){
System.out.print( "*" );
}
System.out.println();
}
System.out.println();
//菱形
int [] o = new int [ 10 ];
for ( int i= 0 ;i<o.length;i++){
for ( int j= 0 ;j<o.length-i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m< 2 *i- 1 ;m++){
System.out.print( "*" );
}
System.out.println();
}
for ( int i= 0 ;i<o.length;i++){
for ( int j= 0 ;j<i;j++){
System.out.print( " " );
}
for ( int m= 0 ;m< 2 *(o.length-i)- 1 ;m++){
System.out.print( "*" );
}
System.out.println();
}
}
}
|
以上就是本文的全部内容,此小程序具有较强的通用性,希望对大家的学习有所帮助。