当前位置:网站首页>双重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、实现效果展示
边栏推荐
- apisix-Getting Started
- About the directory structure of the web application
- ApiPost is really fragrant and powerful, it's time to throw away Postman and Swagger
- 上海交大牵手淘宝成立媒体计算实验室:推动视频超分等关键技术发展
- nacos注册中心
- Differences between i++ and ++i in loops in C language
- golang的time包:时间间隔格式化和秒、毫秒、纳秒等时间戳格式输出的方法
- Use the browser's local storage to realize the function of remembering the user name
- kubernetes affinity, anti-affinity, taint, tolerance
- Redis-集群模式(主从复制模式,哨兵模式,集群化模式)
猜你喜欢
25K测试老鸟6年经验的面试心得,四种公司、四种问题…
MySQL数据表的基本操作和基于 MySQL数据表的基本操作的综合实例项目
如何优化OpenSumi终端性能?
The company does not pay attention to software testing, and the new Ali P8 has written a test case writing specification for us
Differences between i++ and ++i in loops in C language
为什么4个字节的float要比8个字节的long大呢?
Google 安装印象笔记剪藏插件
【C语言】LeetCode26.删除有序数组中的重复项&&LeetCode88.合并两个有序数组
Matlab论文插图绘制模板第41期—气泡图(bubblechart)
leetcode每天5题-Day04
随机推荐
Integrate ssm (1)
Polar Parametrization for Vision-based Surround-View 3D Detection 论文笔记
复盘:图像饱和度计算公式和图像信噪(PSNR)比计算公式
Features and installation of non-relational database MongoDB
leetcode每天5题-Day04
服务器的单机防御与集群防御
关于 VS Code 优化启动性能的实践
Block elements, inline elements (
elements, span elements)Point Density-Aware Voxels for LiDAR 3D Object Detection 论文笔记
The Go language learning notes - dealing with timeout - use the language from scratch from Context
Redis集群模式
Mysql数据库 | 基于Docker搭建Mysql-8.0以上版本主从实例实战
Go language study notes - grpc serverclient protobuf Go language from scratch
程序员最重要的能力是什么?
51单片机外设篇:ADC
区块元素、内联元素(<div>元素、span元素)
Redis-----非关系数据库
5款经典代码阅读器的使用方案对比
C language entry combat (13): decimal number to binary
PIL与numpy格式之间的转换