1. 程式人生 > 其它 >用IDEA列印一個菱形

用IDEA列印一個菱形

package com.tu.struct;
//整個程式打印出
/*
*
***
*****
*******
*********
*******
*****
***
*

*/
public class TestDemo {
public static void main(String[] args) {
//列印三角形 5行
/*
*
***
*****
*******
*********
*/
for (int i = 1; i <= 5; i++) {
for (int j = 5; j >i; j--) {
System.out.print(" ");
}

for (int j = 1; j <= i; j++) {
System.out.print("*");
}
for (int j = 1; j <i; j++) {
System.out.print("*");
}
System.out.println();
}


//下面的語句打印出
/*
*******
*****
***
*
*/
for (int m = 1; m <= 5; m++) {
for (int n = 1; n<=m; n++) {
System.out.print(" ");
}

for (int n = 4; n >= m; n--) {
System.out.print("*");
}
for (int n = 4; n > m; n--) {
System.out.print("*");
}

System.out.println();
}
}
}