当前位置:网站首页>双重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、实现效果展示
边栏推荐
- Introduction to coredns
- C竞赛训练
- MySQL导入sql文件的三种方法
- Navicat new database
- 165.比较版本号
- 如何进行并发数计算(稳定性测试和压力测试)?
- el-input can only input integers (including positive numbers, negative numbers, 0) or only integers (including positive numbers, negative numbers, 0) and decimals
- 利用浏览器本地存储 实现记住用户名的功能
- 国际顶会OSDI首度收录淘宝系统论文,端云协同智能获大会主旨演讲推荐
- classSR论文阅读笔记
猜你喜欢
18 years of programmer career, read more than 200 programming books, pick out some essence to share with you
程序员写PPT的小技巧
面试官:设计“抖音”直播功能测试用例吧
Cyber Security Learning - Intranet Penetration 4
Block elements, inline elements (
elements, span elements)Navicat new database
leetcode一步解决链表反转问题
说好的女程序员做测试有优势?面试十几家,被面试官虐哭~~
上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
[C language] LeetCode26. Delete duplicates in an ordered array && LeetCode88. Merge two ordered arrays
随机推荐
leetcode一步解决链表反转问题
C language: Check for omissions and fill in vacancies (3)
swinIR论文阅读笔记
Cyber Security Learning - Intranet Penetration 4
本周大新闻|苹果MR已进行Pre-EVT测试,Quest 2涨价100美元
Redis-集群模式(主从复制模式,哨兵模式,集群化模式)
关于 VS Code 优化启动性能的实践
Matlab paper illustration drawing template No. 41 - bubble chart (bubblechart)
对node工程进行压力测试与性能分析
Introduction to coredns
coredns介绍
跨桌面端Web容器演进
ApiPost is really fragrant and powerful, it's time to throw away Postman and Swagger
leetcode 665. Non-decreasing Array 非递减数列(中等)
51 MCU peripherals: DS18B20
Introduction and use of apifox (1).
leetcode一步解决链表合并问题
Alluxio为Presto赋能跨云的自助服务能力
Block elements, inline elements (
elements, span elements)Redis database