当前位置:网站首页>双重for循环案例(用js打印九九乘法表)
双重for循环案例(用js打印九九乘法表)
2022-08-02 05:12:00 【枕頭說他不想醒】
1、需要实现的效果:

2、实现思路
(1)一共有9行,因为每一行的个数不一样,所以要用到双重for循环
(2) 外层的是行数i,循环就此,可以打印九行
(3)内层的for控制每行公式j
(4)每一行公式的个数正好和行数一致,j<=i
3、代码段:
<script>
var str = '';
for( var i = 1; i<= 9; i++){ //外层循环控制行数
for( var j =1; j <= i; j++){ //里层控制每行的个数 j<= i
str += j+ '×' + i + '='+i * j + '\t'; //"\t"给每一个公式后面加空格
}
str += '\n'; //"\n"是换行
}
console.log(str);
</script>4、实现效果展示

边栏推荐
- PIL与numpy格式之间的转换
- leetcode一步解决链表合并问题
- golang环境详细安装、配置
- PSQL function, predicate, CASE expression and set operations
- 51单片机外设篇:红外通信
- 网安学习-内网渗透4
- Google 安装印象笔记剪藏插件
- 配合蓝牙打印的encoding-indexes.js文件内容:
- 金山云团队分享 | 5000字读懂Presto如何与Alluxio搭配
- el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
猜你喜欢

Meta公司内部项目-RaptorX:将Presto性能提升10倍

自动化运维工具——ansible、概述、安装、模块介绍

程序员最重要的能力是什么?
[email protected](使用passwordYES)"/>Navicat报错:1045 -拒绝访问用户[email protected](使用passwordYES)

MySql copies data from one table to another table

Redis-----非关系数据库

leetcode一步解决链表反转问题

区块元素、内联元素(<div>元素、span元素)

Review: image saturation calculation formula and image signal-to-noise (PSNR) ratio calculation formula

为什么4个字节的float要比8个字节的long大呢?
随机推荐
leetcode 665. Non-decreasing Array 非递减数列(中等)
C 竞赛——捕鱼
Matlab论文插图绘制模板第41期—气泡图(bubblechart)
golang环境详细安装、配置
LeetCode刷题系列 -- 10. 正则表达式匹配
【解决】RESP.app 连接不上redis
程序员写PPT的小技巧
复盘:图像饱和度计算公式和图像信噪(PSNR)比计算公式
Mysql implements optimistic locking
Meta公司新探索 | 利用Alluxio数据缓存降低Presto延迟
MySql将一张表的数据copy到另一张表中
The original question on the two sides of the automatic test of the byte beating (arranged according to the recording) is real and effective 26
家用 NAS 服务器(4)| MergerFS和SnapRaid数据定时备份
Alluxio为Presto赋能跨云的自助服务能力
关于 VS Code 优化启动性能的实践
ApiPost 真香真强大,是时候丢掉 Postman、Swagger 了
51 MCU Peripherals: Infrared Communication
关于web应用的目录结构
[C language] LeetCode26. Delete duplicates in an ordered array && LeetCode88. Merge two ordered arrays
整合ssm(一)