欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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?"&nbsp;&nbsp;":"&nbsp;"));
                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?"&nbsp;&nbsp;":"&nbsp;")); 
                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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                j++;
            }
            while(j<=9-i)
            }
            var k=1;
            do{
                document.write(i+"*"+k+"="+i*k+(i*k<10?"&nbsp;&nbsp;":"&nbsp;"));
                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("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
                    j++;
                }
                while(j<=9-i)
            }
            var k=i;
            do{
                document.write(i+"*"+k+"="+i*k+(i*k<10?"&nbsp;&nbsp;":"&nbsp;"));
                k--;
            }
            while(k>=1)
            document.write("<br>");
            i--;

        }
        while(i>=1)


    </script>
</head>
<body>
    
</body>
</html>