public class Test {
public static void main(String[] args) {
int row = 0;//行
int col = -5;//列
/*
row
-5-4-3-2-1 * 1 2 3 4 5 0
-5-4-3-2 * * * 2 3 4 5 1
-5-4-3 * * * * * 3 4 5 2
-5-4 * * * * * * * 4 5 3
-5 * * * * * * * * * 5 4
row -5-4-3-2-1 0 1 2 3 4 5
*/
while(true){
if(col>=-row&&col<=row){
System.out.print("* ");
}else{
System.out.print(" ");
}
if(col>row){
row++;//移到下一行
col=-5;//初始化列
System.out.println();
continue;//跳转到循环开始处
}
col++;
if(col==5){//到第5行就跳出循环
System.out.println();
break ;
}
}
}
}
2012年3月12日 22:18