import java.util.Scanner;
class KongXingJuXing {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
System.out.print("请输入 0 - 30之内的数: ");
int x = sc.nextInt() ;
if( x == 0){
System.out.println("结束本次循环!请重新运行!");
break;
}else if(x < 0 || x >30 ){
System.out.println("您输入的错误!");
}else{
for (int i = 1;i<=x ;i++ ) {
if(i == 1 || i == x){
System.out.print(" ");
}else{
System.out.print("* ");
}
for (int j = 1;j <= x ;j++ ) {
if (i == 1 || i == x) { //1. i=1; * j = 1 ~ 5 *****
System.out.print("* ");
}
if(i >=2 && i < x){
System.out.print(" ");
}
}
if(i <= x) // 1. i=1; * ,j = 1 ~ 5 ***** ,1<5 *
// 2. i=2; * ,j = 1 ~ 5 ..... ,2<5 *
System.out.print("*");
System.out.println();
}
}
}
}
}
|
|