打印出如下图案(菱形)
public class Fr {
public static void main(String[] args) {
for ( int i = 1; i <= 4; i++) { //行数
for(int k=0;k<=4-i;k++) { //输出每一行空格
System.out.print(" ");
}
for ( int j = 1; j <= 2 * i - 1; j++) //打印* 1*2-1 2*2-1 3*2-1 4*2-1
System.out.print("*");
}
System.out.println();
}
}
*
***
*****
*******
第二种方法:
public class Fr { public static void main(String[] args) { for ( int i = 1; i <= 5; i++) { //行数 for(int k=0;k<=5-i;k++) { //输出每一行空格 System.out.print(" "); } for ( int j = 1; j <=i; j++) { System.out.print("* "); } System.out.println(); } } } * * * * * * * * * * * * * * *