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
|
package
上机练习;
import
java.util.Scanner;
public
class
A06 {
/**
* @param args
*/
public
static
void
main(String[] args) {
// TODO Auto-generated method stub
Scanner input =
new
Scanner (System.in);
System.out.println(
"请输入菱形的行数:"
);
int
rows = input.nextInt();
while
(rows%
2
==
0
){
System.out.println(
"请输入奇数:"
);
rows = input.nextInt();
}
int
n=(rows+
1
)/
2
;
for
(
int
i =
1
; i <=n; i++) {
for
(
int
j =
1
; j <=n-i; j++) {
System.out.print(
" "
);
}
for
(
int
k =
1
; k <=
2
*i-
1
; k++) {
System.out.print(
"*"
);
}
System.out.println();
}
for
(
int
i =n-
1
; i>
0
; i--) {
for
(
int
n1 = i; n1 <rows-i; n1++) {
System.out.print(
" "
);
}
for
(
int
j =
1
; j <=
2
*i-
1
; j++) {
System.out.print(
"*"
);
}
System.out.print(
"\n"
);
}
}
}
|
本文转自 Y幕徐 51CTO博客,原文链接:http://blog.51cto.com/765133133/1426310