当前位置:网站首页>How to output a digital diamond with a for loop
How to output a digital diamond with a for loop
2022-07-19 07:21:00 【Walk in the clouds】
It is required to output the following diamonds :
Code :
public static void main(String[] args) {
int totalRow = 7;
for (int row = 0; row < totalRow; row++) {
// The number of spaces on the left
int leftSpaceNum = Math.abs(totalRow / 2 - row);
// The maximum value in the middle of each line
int colMid = totalRow / 2 - leftSpaceNum + 1;
// Number of numbers
int number = totalRow-2*Math.abs(totalRow/2-row);
for (int col = 0; col < totalRow; col++) {
if (col < leftSpaceNum) {
System.out.print(" ");
}else if(col < number+leftSpaceNum) {
System.out.print(colMid - Math.abs(totalRow/2-col) + " ");
}else {
break;
}
}
System.out.println();
}
}
边栏推荐
- 4. Installation and use of idea
- Edit close automatically generate configuration file when saving
- Quickly master the sort command and tr command
- M analysis of anti-interference performance of high-speed frequency hopping communication system based on Simulink
- 爬虫基础—代理的基本原理
- 2021-10-25 browser compatibility problems
- PyTorch学习日记(二)
- 字典,集合的使用,数据类型的转换
- 论文阅读:Deep Residual Shrinkage Networksfor Fault Diagnosis
- PyTorch学习日记(四)
猜你喜欢

JS不使用async/await解决数据异步/同步问题

m在VBLAST协作MIMO系统分部使用LDPC,Turbo,卷积三种信道编译码进行误码率matlab仿真

网络知识-04 网络层-IPv6

Network knowledge-03 data link layer PPP

Fundamentals of crawler - basic principles of agent

Quickly learn to use cut command and uniq command

Mapping rule configuration of zuul route

My world 1.12.2 Magic Baby (Fairy treasure dream) service opening tutorial

M simulation of cooperative MIMO distributed space-time coding technology based on MATLAB

m基于simulink的16QAM和2DPSK通信链路仿真,并通过matlab调用simulink模型得到误码率曲线
随机推荐
m基于MATLAB-GUI的GPS数据经纬度高度解析与kalman分析软件设计
Sword finger offer question brushing record - offer 07 Rebuild binary tree
M design of GPS data longitude and latitude height analysis and Kalman analysis software based on matlab-GUI
网络知识-03 数据链路层-以太网
Review of 4121 Computer System for Data Science
Matlab implementation code of image denoising method based on Hidden Markov tree model in wavelet domain
The use and differences of dictionaries, tuples and lists,
[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
Recursive access to directories, print Fibonacci sequences, high-order functions
网络知识-05 传输层-TCP
网络知识-04 网络层-IPv6
My world 1.18.1 forge version open service tutorial, can install mod, with panel
Cracking Metric/Business Case/Product Sense Problems
Execute shell script under Linux to call SQL file and transfer it to remote server
ivew 穿梭框Transfer组件高亮显示操作值
The principle of SYN Flood attack and the solution of SYN Flood Attack
Network knowledge-04 network layer IPv4 protocol
Paper reading: deep residual learning in spiking neural networks
m基于matlab的DQPSK调制解调技术的仿真
PyTorch学习日记(四)