我自己写的,这个地方看你想打几行就在print()方法输入多少就行,你开心就好。
class Prog {
public static void main(String[] args) {
print(10);
}
public static void print(int n){
int count = 1;
for (int i = 1;i < 2*n;i++){
if(i < n){
for (int j = 1;j <= n-i;j++) {
System.out.print(" ");
}
for (int x = 1;x <= count;x++) {
System.out.print("*");
}
count += 2;
}else{
for (int j = 1;j <= i-n;j++) {
System.out.print(" ");
}
for (int x = 1;x <= count;x++) {
System.out.print("*");
}
count -= 2;
}
System.out.println();
}
}
} |