JS打印输出各种形状
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
</title>
</head>
<script type="text/javascript">
document.writeln("打印不同形状<br/>")
//打印不同形状
document.writeln("*<br/>");
//打印一颗*
document.writeln("============<br/>")
for (var i = 0; i < 6; i++) {
document.writeln("*");
}
//打印一行6颗*
document.writeln("<br/>")
document.writeln("============<br/>")
for (var j = 0; j < 6; j++) {
document.writeln("*<br/>");
}
//打印6行一列*
document.writeln("============<br/>")
for (var k = 0; k < 6; k++) {
for (var l = 0; l < 6; l++) {
document.writeln("*");
}
document.writeln("<br/>");
}
//打印6行6列*
document.writeln("============<br/>")
for (var m = 0; m < 6; m++) {
for (var n = 5; n > m; n--) {
document.writeln(" ");
}
for (var o = 0; o < 2 * m + 1; o++) {
document.writeln("*");
}
document.writeln("<br/>");
}
//打印6行11列*三角形金字塔形状
document.writeln("============<br/>")
for (var p = 0; p < 6; p++) {
for (var q = 5; q > p; q--) {
document.writeln(" ");
}
for (var r = 0; r < 2 * p + 1; r++) {
document.writeln("*");
}
document.writeln("<br/>");
}
//打印菱形上半部分*
for (var s = 5; s > 0; s--) {
for (var t = 6; t > s; t--) {
document.writeln(" ");
}
for (var u = 0; u < 2 * s - 1; u++) {
document.writeln("*");
}
document.writeln("<br/>");
}
//打印完整实心菱形
document.writeln("============<br/>")
</script>
<body>
</body>
</html>
共同学习,写下你的评论
评论加载中...
作者其他优质文章