类似阶梯波浪形效果,如何用循环实现
请指教。
后面数字还有很多,因此尽量循环实现
public static void main(String[] args) {
//峰值
int high= 9;
//结束数字
int breakNum = 21;
int a = 1;
while (true){
for (int i = 1; i < high; i++) {
for (int j = 0; j < i; j++) {
if (j==i-1){
System.out.println(a++);
if (a==breakNum+1){
return;
}
}else{
System.out.print("*");
}
}
}
for (int i = high; i > 1; i--) {
for (int j = 0; j < i; j++) {
if (j==i-1){
System.out.println(a++);
if (a==breakNum+1){
return;
}
}else{
System.out.print("*");
}
}
}
}
}