打印菱形
思路分析:
- 菱形是平行四边形,
- 从上到下依次按行打印
- 在边的位置打印星号, 在其它的位置打印空格
public class 第十九题打印菱形 {public static void main(String[] args) {int count = 14;//打印菱形上部for(int i = 1; i <= 7; i+=2 ) {//打印空格count-=2;for(int k = count; k > 3; k--) {System.out.print(" ");}for(int j = 1; j <= i; j++) {System.out.print("*" + " ");}System.out.println();}count = 1;//打印菱形下部for(int i = 5; i > 0; i -=2) {count+=2;//打印空格for(int j=0; j <= count; j++) {System.out.print(" ");}//打印星星for(int k = i; k > 0; k --) {System.out.print(" "+ "*");}System.out.println();}}
}