当前位置:网站首页>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
边栏推荐
- ext4文件系统打开了DIR_NLINK特性后,link_count超过65000的后使用link_count=1来表示数量不可知
- Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
- redis原理和使用-安装和分布式配置
- 838. Heap sorting
- Li Mu D2L (IV) -- softmax regression
- Pat grade a a1013 battle over cities
- 【Mysql】认识Mysql重要架构(一)
- The essence of attack and defense strategy behind the noun of network security
- JVM触发minor gc的条件
- 李沐d2l(四)---Softmax回归
猜你喜欢
随机推荐
2B和2C
jvm命令归纳
760. 字符串长度
PHP 之 Apple生成和验证令牌
Redis principle and use - Basic Features
Under a directory of ext3 file system, subfolders cannot be created, but files can be created
CF1481C Fence Painting
滑动窗口、双指针、单调队列、单调栈
Bloom filter
tornado之多进程服务
Codeworks DP collection
(2006,Mysql Server has gone away)问题处理
MySQL strengthen knowledge points
2022 Shanghai safety officer C certificate examination questions and mock examination
李沐d2l(六)---模型选择
谷粒学院的全部学习源码
多项式开根
csdn空格用什么表示
Selection and practice of distributed tracking system
Clean the label folder