import java.util.Arrays;
import java.util.Scanner;
public class Shuju5 {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print("请输入菱形行数:");
int line = input.nextInt();
while(line%2==0) {
System.out.print("请输入奇数:");
line = input.nextInt();
}
int line1 = (line+1)/2;
for(int i=1;i<=line1;i++) {
for(int j=1;j<=line1-i;j++) {
System.out.print(" ");
}
for(int k=1;k<=2*i-1;k++) {
System.out.print("*");
}System.out.println("");
}
for(int i=1;i<=line1-1;i++) {
for(int j=1;j<=i;j++) {
System.out.print(" ");
}
for(int k=1;k<=line-2*i;k++) {
System.out.print("*");
}System.out.println("");
}
}
}
第八章循环进阶
最新推荐文章于 2020-09-08 20:43:36 发布