js:用do while循环写出四种格式乘法表
程序员文章站
2024-03-23 21:32:40
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>do_while乘法表</title>
<style>
html{
font-family: monospace;
}
</style>
<script>
document.write("格式一:");
document.write("<br><br>");
var i=1;
do{
var j=1;
do{
document.write(i+"*"+j+"="+i*j+(i*j<10?" ":" "));
j++;
}
while(j<=i)
document.write("<br>");
i++;
}
while(i<=9)
document.write("<br>");
document.write("格式二:");
document.write("<br><br>");
var i=9;
do{
var j=1;
do{
document.write(i+"*"+j+"="+i*j+(i*j<10?" ":" "));
j++;
}
while(j<=i)
document.write("<br>");
i--;
}
while(i>=1)
document.write("<br>");
document.write("格式三:");
document.write("<br><br>");
var i=1;
do{
if(i!=9){
var j=1;
do{
document.write(" ");
j++;
}
while(j<=9-i)
}
var k=1;
do{
document.write(i+"*"+k+"="+i*k+(i*k<10?" ":" "));
k++;
}
while(k<=i)
document.write("<br>")
i++;
}
while(i<=9)
document.write("<br>");
document.write("格式四:");
document.write("<br><br>");
var i=9;
do{
if(i!=9){
var j=1;
do{
document.write(" ");
j++;
}
while(j<=9-i)
}
var k=i;
do{
document.write(i+"*"+k+"="+i*k+(i*k<10?" ":" "));
k--;
}
while(k>=1)
document.write("<br>");
i--;
}
while(i>=1)
</script>
</head>
<body>
</body>
</html>
上一篇: 《算法笔记》2.7小节