<meta charset=utf-8>
<font>按照要求打印星星:外层循环决定行数,内层循环决定每一层的个数</font>
<hr>
<font>在同一行显示5颗星星</font><br>
<script type="text/javascript">
for(i=1;i<=5;i++){
document.write("*");
}
</script>
<hr>
<font>打印三行都显示5颗星星</font><br>
<script type="text/javascript">
for(i=1;i<=3;i++){
for(j=1;j<=5;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>打印根据行数的不同显示与行数相同的星星</font><br>
<script type="text/javascript">
for(i=1;i<=5;i++){
for(j=1;j<=i;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>每增加一行,就多打印两个星星</font><br>
<script type="text/javascript">
for(i=1;i<=5;i++){
for(j=1;j<=2*i-1;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>倒序打印星星个数</font><br>
<script type="text/javascript">
for(i=5;i>=1;i--){
for(j=1;j<=i;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>倒序打印将星星都移到最中间的排列</font><br>
<script type="text/javascript">
for(i=5;i>=1;i--){
for(k=1;k<=6-i;k++){
document.write(" ");
}
for(j=1;j<=i;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>正序打印将星星都移到最中间的排列</font><br>
<script type="text/javascript">
for(i=1;i<=5;i++){
for(k=1;k<=6-i;k++){
document.write(" ");
}
for(j=1;j<=i;j++){
document.write("*");
}
document.write("<br>");
}
</script>
<hr>
<font>第一行打印5颗星,第二行,第三行,第四行打印2颗星(中间有空格),第五行打印五颗星</font><br>
<script type="text/javascript">
for(i=1;i<=5;i++){
for(k=1;k<=6-i;k++){
document.write(" ");
}
for(j=1;j<=5;j++){
if(i>=2&&i<=4&&j>=2&&j<=4){
document.write(" ");
}else{
document.write("*");
}
}
document.write("<br>");
}
</script>