九九乘法表在js中编程
程序员文章站
2022-07-04 19:11:02
...
九九乘法表在js中编程
for(var j=1; j<=9;j++){
var result = "";
for(var i=1;i<=j;i++){
result +=(i+"*"+j+" = "+i*j+(i*j>9?" ":" "));
}
console.log(result);
}
console.log("第2个");
for(var j=9; j>=1;j--){
var result = "";
for(var i=1;i<=j;i++){
result +=(i+"*"+j+" = "+i*j+(i*j>9?" ":" "));
}
console.log(result);
}
console.log("第3个");
for(var j=1; j<=9;j++){
var result = "";
for(var i=9;i>0;i--){
if(i>j){
result +=" ";
}else{
result +=(i+"*"+j+" = "+i*j+(i*j>9?" ":" "));
}
}
console.log(result);
}
console.log("第4个");
for(var j=9; j>=0;j--){
var result = "";
for(var i=9;i>0;i--){
if(i>j){
result +=" ";
}else{
result +=(i+"*"+j+" = "+i*j+(i*j>9?" ":" "));
}
}
console.log(result);
}
推荐阅读