当前位置:网站首页>双重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、实现效果展示

边栏推荐
猜你喜欢

深度学习——CNN实现MNIST手写数字的识别

Cyber Security Learning - Intranet Penetration 4

Redis-集群模式(主从复制模式,哨兵模式,集群化模式)

C language: Check for omissions and fill in vacancies (3)

Google 安装印象笔记剪藏插件

Use the browser's local storage to realize the function of remembering the user name

为什么4个字节的float要比8个字节的long大呢?

Stress testing and performance analysis of node projects

说好的女程序员做测试有优势?面试十几家,被面试官虐哭~~

51单片机外设篇:ADC
随机推荐
使用TinkerPop框架对GDB增删改查
复盘:图像饱和度计算公式和图像信噪(PSNR)比计算公式
classSR论文阅读笔记
leetcode一步解决链表合并问题
Navicat cannot connect to mysql super detailed processing method
nacos注册中心
About the directory structure of the web application
关于鸿蒙系统 JS UI 框架源码的分析
Constructors, member variables, local variables
网安学习-内网渗透4
MySQL数据表的基本操作和基于 MySQL数据表的基本操作的综合实例项目
构造方法、成员变量、局部变量
apisix-入门使用篇
ApiPost is really fragrant and powerful, it's time to throw away Postman and Swagger
配合蓝牙打印的encoding-indexes.js文件内容:
21天学习挑战赛安排
How much does a test environment cost? Start with cost and efficiency
[PSQL] 函数、谓词、CASE表达式、集合运算
5款经典代码阅读器的使用方案对比
字节面试题:如何保证缓存和数据库的一致性