public class WeekendDemo01 {
/** 打印菱形
* *
* ***
* *****
* ***
* *
*/
public static void main(String[] args) {
int bianchang;//记录边长
int count02;//控制打印*次数
System.out.println("菱形边长设置为:");
Scanner scanner = new Scanner(System.in);
bianchang = scanner.nextInt();
System.out.println(bianchang);
//i控制总循环次数
for (int i = 1; i <= bianchang; i++) {
//控制打印空格次数
for (int j = i; j <= bianchang; j++) {
System.out.print(" ");
}
//控制打印*次数
for (int c = 0; c < 2*i-1; c++) {
System.out.print("*");
}
System.out.println();
}
for(int i = 0;i < bianchang-1;i++){
//打印空格
for(int j = 0;j <= i+1;j++){
System.out.print(" ");
}
for(int c = 1;c < 2*bianchang-2*i-2;c++){
System.out.print("*");
}
System.out.println();
}
}
}
标签:bianchang,java,scanner,int,打印,System,菱形 From: https://www.cnblogs.com/xiaoto9426/p/16728625.html