//输入边长,输出菱形
import java.util.*;
class Dome1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("请输入菱形的边长(2-30):");
int a = sc.nextInt();
if (a>1 && a < 32 ) {
for(int i = 0; i < a; i++) {
for (int k = 0;k<a+10-i ;k++ ) {
System.out.print(" ");
}
for(int j = 0; j <= i; j++) {
System.out.print("* ");
}
System.out.println();
}
for(int i = a; i >=0; i--) {
for (int k = a+10 - i;k>0 ;k-- ) {
System.out.print(" ");
}
for(int j = i; j >=0; j--) {
System.out.print("* ");
}
System.out.println();
}
break;
} else {
System.out.println("你是不是傻,请重新输入:");
}
}
}
}
|
|