当前位置:网站首页>JS output diamond on the console
JS output diamond on the console
2022-07-26 09:19:00 【Xiaomeng new admission】
js Output diamond on the console
With a top half 10 That's ok , The second part of 9 Line as an example
var str = ""; // String splicing shall be adopted for console output , So first define an empty string
for (var row = 1; row <= 10; row++) { // The outer loop controls the number of lines , First output the top half 10 That's ok
for (var j = 1; j <= 10 - row; j++) { // Because the first line has 9 A space , 1 A star . In order to be more straightforward , use @ Replace spaces
str = str + "@" // Because the second line has 8 A space , 3 A star
} // Because the third line has 7 A space , 5 A star
// Because the fourth line has 6 A space , 7 A star
// ...........
// Because the tenth line has 0 A space ,19 A star
// So the relationship between spaces and the number of lines is :j<=(10-row)
for (var i = 1; i <= 2 * row - 1; i++) { // The relationship between stars and the number of rows is :(2*row-1)
str = str + "*";
}
str = str + "\n"; // The outer loop , Every output line should be wrapped
}
// The lower half is roughly the same as the upper half
for (var row = 1; row <= 9; row++) { // The outer loop controls the number of lines , Output the lower half of 9 That's ok
for (var j = 1; j <= row; j++) { // Because the first line has 1 A space ,17 A star
str = str + "@" // Because the second line has 1 A space ,15 A star
} // Because the third line has 1 A space ,13 A star
// Because the fourth line has 1 A space ,11 A star
//...............
// Because the first line has 9 A space , 1 A star
// So the relationship between spaces and the number of lines is :j<=row
for (var i = 1; i <= 19 - 2 * row; i++) { // The relationship between stars and the number of rows is the total number of rows 19 subtract 2 Times row namely :19-2*row
str = str + "*";
}
str = str + "\n"; // The outer loop , Every output line should be wrapped
}
console.log(str);

I copied it directly , ha-ha ! For your reference !
See both , Good luck !
————————————————
Copyright notice : This paper is about CSDN Blogger 「Fire1122」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/Fire1122/article/details/108308918
边栏推荐
- Li Mu D2L (VI) -- model selection
- 论文笔记: 知识图谱 KGAT (未完暂存)
- 本地缓存
- 字节缓冲流&字符流详解
- [arkit, realitykit] turn pictures into 3D models
- LeetCode三数之和问题
- Error: cannot find module 'UMI' problem handling
- Force button list question
- 多项式开根
- Order based evaluation index (especially for recommendation system and multi label learning)
猜你喜欢

Voice chat app source code - Nath live broadcast system source code

李沐d2l(五)---多层感知机
![[MySQL] detailed explanation of MySQL lock (III)](/img/3c/c6b5aa5693e6e7b5730a286d988c82.png)
[MySQL] detailed explanation of MySQL lock (III)

Innovus卡住,提示X Error:

2022 mobile crane driver test question simulation test question bank simulation test platform operation

【Mysql】一条SQL语句是怎么执行的(二)

语音聊天app源码——钠斯直播系统源码

高数 | 武爷『经典系列』每日一题思路及易错点总结

Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown

Mysql事务
随机推荐
838. Heap sorting
760. 字符串长度
Original root and NTT 5000 word explanation
Qt | 关于如何使用事件过滤器 eventFilter
Innovus is stuck, prompting x error:
谷粒学院的全部学习源码
756. Serpentine matrix
2022 tea artist (intermediate) special operation certificate examination question bank simulated examination platform operation
聪明的美食家 C语言
论文笔记: 知识图谱 KGAT (未完暂存)
您的登录IP不在管理员配置的登录掩码范围内
Force button list question
2022 chemical automation control instrument operation certificate test question simulation test platform operation
布隆过滤器
What is the difference between NFT and digital collections?
【Mysql】一条SQL语句是怎么执行的(二)
Use of off heap memory
Redis principle and usage - installation and distributed configuration
Li Mu D2L (IV) -- softmax regression
unity简易消息机制