/**
* @Author
* @Description //TODO 2*n+1菱形
* @Date
* @Param int
* @return
**/
public static void printLing(int num) {
//上半部分n+1=num行
for (int i = 0; i < num; i++) {
//0 1 2 3
for (int j = num; j - i > 0; j--) {
//打印空格
System.out.print(" ");
}
//打印(2i+1)*
for (int j = 0; j < 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
//下半部分
for (int i = 0; i < num; i++) {
for (int j = num; i + j >= num - 1; j--) {
//打印空格
System.out.print(" ");
}
//下半部分第一行(num-1)*2-1 个*
for (int j = (num - 1) * 2 - 1; j > 2 * i; j--) {
System.out.print("*");
}
System.out.println();
}
}
标签:num,int,打印,System,菱形,使用,print,out From: https://www.cnblogs.com/caoaman/p/17178023.html