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

边栏推荐
猜你喜欢

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

【C语言】LeetCode26.删除有序数组中的重复项&&LeetCode88.合并两个有序数组

国际顶会OSDI首度收录淘宝系统论文,端云协同智能获大会主旨演讲推荐

Google 安装印象笔记剪藏插件

无代码生产新模式探索

Polar Parametrization for Vision-based Surround-View 3D Detection 论文笔记

JUC(一)- JUC学习概览 - 对JUC有一个整体的认识

There are more and more talents in software testing. Why are people still reluctant to take the road of software testing?

关于鸿蒙系统 JS UI 框架源码的分析

OAuth 授权协议 | 都云原生时代了,我们应该多懂一点OAuth ?
随机推荐
51 MCU peripherals: DS18B20
深度学习——CNN实现MNIST手写数字的识别
swinIR论文阅读笔记
Detailed explanation of the software testing process (mind map) of the first-tier manufacturers
为什么4个字节的float要比8个字节的long大呢?
驱动页面性能优化的3个有效策略
程序员写PPT的小技巧
服务器的单机防御与集群防御
ERROR 1045 (28000) Access denied for user 'root'@'localhost'Solution
C语言小游戏——扫雷小游戏
Redis数据库
leetcode括号匹配问题——32.最长有效括号
How H5 realizes evoking APP
Mysql implements optimistic locking
Timing task library in the language use Cron, rounding
C 竞赛——捕鱼
golang环境详细安装、配置
C language entry combat (13): decimal number to binary
Three methods of importing sql files in MySQL
Packaging and deployment of go projects