第八章 6

package a8;


import java.util.Scanner;


public class C6 {
public static void main(String[] args) {
System.out.print("请输入菱形行数:");
Scanner input = new Scanner(System.in);
int rows = input.nextInt();
while (rows%2 == 0) {
System.out.print("请输入奇数:");
rows = input.nextInt();
}
for (int i = 1;i <= rows;i++) {
if(i <= (rows+1)/2) {
for(int j = 1;j <= (rows+1)/2-i;j++) {
System.out.print(" ");

for (int k = 1; k <= 2*i-1 ; k++) {
System.out.print("*");
}
System.out.println();
} else {
for (int j = 1; j <= i-(rows+1)/2 ; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2*(rows-i)+1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
}

猜你喜欢

转载自blog.csdn.net/lsxdbd/article/details/79853754