今天无聊随便写一下以前在学校里面老师布置一题作业。想想当年脑子都想破了都写不出来,今天不小心看到以前没有完成的作业,花10钟完成了。想想也没有那么难的啊,嘎嘎。。。
package com;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int p=10;
//正三角形的实现
for(int i=1;i<=p;i++){
for(int x=1;x<=p-i;x++){
System.out.print(" ");
}
for(int y=1;y<=2*i-1;y++){
System.out.print("*");
}
System.out.println();
}
//倒正三角形的实现
for(int n=p;n>0;n--){
for(int m=1;m<=p-n;m++){
System.out.print(" ");
}
for(int y=1;y<=2*n-1;y++){
System.out.print("*");
}
System.out.println();
}
}
}
运行结果 *
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*