for(var n=5; n>=-5; n--){//循环打印行
for(var i=-5; i<=5; i++){//循环打印列
if(Math.abs(n)+Math.abs(i)<=5){//当行和列的绝对值相加<=5时,打印*
document.write("*");
}else{//否则打印空格,这里用-代替
document.write("-");
}
}
document.write("<br>");//第一行打印完成,换行显示
}
打印菱形
最新推荐文章于 2019-08-25 19:46:07 发布