当前位置:网站首页>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
边栏推荐
- "No input file specified" problem handling
- 838. 堆排序
- Conditions for JVM to trigger minor GC
- Canal 的学习笔记
- 【Mysql】redo log,undo log 和binlog详解(四)
- JS - DataTables 关于每页显示数的控制
- Where are the laravel framework log files stored? How to use it?
- Bloom filter
- JS - DataTables control on the number of displays per page
- 【final关键字的使用】
猜你喜欢

NTT(快速数论变换)多项式求逆 一千五百字解析

Stm32+mfrc522 completes IC card number reading, password modification, data reading and writing

Introduction to excellent verilog/fpga open source project (30) - brute force MD5

对标注文件夹进行清洗

Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain

Cat安装和使用

Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world

The Child and Binary Tree-多项式开根求逆

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points

Ext4 file system opens dir_ After nlink feature, link_ Use link after count exceeds 65000_ Count=1 means the quantity is unknown
随机推荐
李沐d2l(六)---模型选择
Elastic APM安装和使用
Datax的学习笔记
2022 chemical automation control instrument operation certificate test question simulation test platform operation
Processing of inconsistent week values obtained by PHP and MySQL
Study notes of dataX
Redis principle and usage - installation and distributed configuration
Codeworks DP collection
Innovus卡住,提示X Error:
Horizontal comparison of the data of the top ten blue chip NFTs in the past half year
839. 模拟堆
Two tips for pycharm to open multiple projects
[online problem] timeout waiting for connection from pool problem troubleshooting
2022年上海市安全员C证考试试题及模拟考试
Zipkin installation and use
垂直搜索
基于序的评价指标 (特别针对推荐系统和多标签学习)
Elastic APM installation and use
unity TopDown角色移动控制
The child and binary tree- open root inversion of polynomials