矩形星星( *)图案
public class ForDemo {
public static void main(String
[] args
) {
for (int i
= 0; i
< 4; i
++) {
for (int j
= 0; j
< 5; j
++) {
System
.out
.print("*");
}
System
.out
.println();
}
}
}
九九乘法表
public class ForDemo {
public static void main(String
[] args
) {
for (int i
= 1; i
<= 9; i
++) {
for (int j
= 1; j
<=i
; j
++) {
System
.out
.print(j
+"*"+i
+"="+(j
*i
)+"\t\t");
}
System
.out
.println();
}
}
}
平行四边形星星( *)图案
public class ForDemo {
public static void main(String
[] args
) {
for (int i
= 1; i
<=5; i
++) {
for (int j
= 1; j
<= 5 - i
; j
++) {
System
.out
.print(" ");
}
for (int k
= 1; k
<= 5; k
++) {
System
.out
.print("*");
}
System
.out
.println();
}
}
}
三角形星星( *)图案
public static void main(String
[] args
) {
for (int i
= 0; i
< 5; i
++) {
for (int j
= i
+ 1; j
< 5; j
++) {
System
.out
.print(" ");
}
for (int k
= 0; k
<= i
; k
++) {
System
.out
.print("* ");
}
System
.out
.println();
}
}
菱形星星(*)图案
public class Diamond {
public static void main(String
[] args
){
print(8);
}
public static void print(int size
) {
if (size
% 2 == 0) {
size
++;
}
for (int i
= 0; i
< size
/ 2 + 1; i
++) {
for (int j
= size
/ 2 + 1; j
> i
+ 1; j
--) {
System
.out
.print("");
}
for (int j
= 0; j
< 2 * i
+ 1; j
++) {
System
.out
.print("*");
}
System
.out
.println();
}
for (int i
= size
/ 2 + 1; i
< size
; i
++) {
for (int j
= 0; j
< i
- size
/ 2; j
++) {
System
.out
.print("");
}
for (int j
= 0; j
< 2 * size
- 1 - 2 * i
; j
++) {
System
.out
.print("*");
}
System
.out
.println();
}
}
}
转载请注明原文地址: https://mac.8miu.com/read-2207.html