我尝试过打印 3*5 盒*(星)图案程序,但无法使其正确格式化。任何人都可以指导我的错误并帮助纠正吗?
下面是 JavaScript 代码:
// Getting input via STDIN
const readline = require("readline");
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
//start-here
var i,j,a=3,b=5;
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
console.log("*");
}
console.log("\n");
}
//end-here
});
Run Code Online (Sandbox Code Playgroud)
输出:
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
Run Code Online (Sandbox Code Playgroud)
需要得到这样的输出:
*****
*****
*****
Run Code Online (Sandbox Code Playgroud)