当前位置:网站首页>双重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、实现效果展示
边栏推荐
- 国际顶会OSDI首度收录淘宝系统论文,端云协同智能获大会主旨演讲推荐
- Redis-集群模式(主从复制模式,哨兵模式,集群化模式)
- nacos注册中心
- Cyber Security Learning - Intranet Penetration 4
- Differences between i++ and ++i in loops in C language
- 整合ssm(一)
- Mysql实现乐观锁
- Meta公司新探索 | 利用Alluxio数据缓存降低Presto延迟
- el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
- nacos registry
猜你喜欢
apifox介绍及使用(1)。
OAuth 授权协议 | 都云原生时代了,我们应该多懂一点OAuth ?
淘系资深工程师整理的300+项学习资源清单(2021最新版)
51 MCU peripherals: ADC
Redis-cluster mode (master-slave replication mode, sentinel mode, clustering mode)
MySQL implements sorting according to custom (specified order)
金山云团队分享 | 5000字读懂Presto如何与Alluxio搭配
21 Day Learning Challenge Schedule
本周大新闻|苹果MR已进行Pre-EVT测试,Quest 2涨价100美元
字节面试题:如何保证缓存和数据库的一致性
随机推荐
测试技术之APP蓝牙连接测试
golang generics
对node工程进行压力测试与性能分析
Detailed installation and configuration of golang environment
Integrate ssm (1)
apisix-入门使用篇
Brush LeetCode topic series - 10. Regular expression match
Shuttle + Alluxio 加速内存Shuffle起飞
Introduction and use of apifox (1).
如何优化OpenSumi终端性能?
配合蓝牙打印的encoding-indexes.js文件内容:
Features and installation of non-relational database MongoDB
Difference and analysis of CPU usage and load
整合ssm(一)
51 microcontroller peripherals article: dot-matrix LCD
swinIR论文阅读笔记
Review: image saturation calculation formula and image signal-to-noise (PSNR) ratio calculation formula
MYSQL unique constraint
PIL与numpy格式之间的转换
21天学习挑战赛安排