当前位置:网站首页>用for循环怎么输出数字菱形啊
用for循环怎么输出数字菱形啊
2022-07-17 05:23:00 【£漫步 云端彡】
要求输出如下菱形:
代码:
public static void main(String[] args) {
int totalRow = 7;
for (int row = 0; row < totalRow; row++) {
// 左边空格数
int leftSpaceNum = Math.abs(totalRow / 2 - row);
//每行中间最大值
int colMid = totalRow / 2 - leftSpaceNum + 1;
// 数字个数
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();
}
}
边栏推荐
- Performance evaluation and comparison of lightweight application servers of major cloud service manufacturers, Alibaba cloud, Tencent cloud, Huawei cloud, and ucloud
- m基于Lorenz混沌自同步的混沌数字保密通信系统的FPGA实现,verilog编程实现,带MATLAB混沌程序
- Homework
- CDN是什么?使用CDN有什么优势?
- 怎么知道网络是否需要用高防服务器?怎么选择机房也是很重要的一点以及后期业务的稳定性
- 天翼雲 杭州 雲主機(VPS) 性能評測
- Hermit crab and anemone
- Paper reading: deep residual shrink networks for fault diagnosis
- How does legend open its service? What do you need to prepare to open legend private server?
- Yuanzi racehorse.
猜你喜欢

urllib库的使用

数据保护/磁盘列阵RAID保护 IP段103.103.188.xxx
![[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :](/img/dd/054af819c8bdca31bd135495386fb4.png)
[ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :

快速学会cut命令,uniq命令的使用

PyTorch学习日记(四)

How to set primary key self growth in PostgreSQL database
![[automated testing] - robotframework practice (III) writing test cases](/img/2e/bbf4a3e348f2a1f5d0b8deceff4634.png)
[automated testing] - robotframework practice (III) writing test cases

M simulation of DQPSK modulation and demodulation technology based on MATLAB

5G时代服务器在这里面起着什么作用?

PyTorch学习日记(四)
随机推荐
Pytorch learning diary (III)
Hermit crab and anemone
PyTorch学习日记(三)
Arm server building my world (MC) version 1.18.2 private server tutorial
剑指Offer刷题记录——Offer 07.重建二叉树
[untitled]
Matlab implementation code of image denoising method based on Hidden Markov tree model in wavelet domain
Minecraft bedrock BDS service tutorial
我的世界 1.18.1 Forge版 开服教程,可装MOD,带面板
快速学会cut命令,uniq命令的使用
How does the advanced anti DDoS server confirm which are malicious ip/ traffic? ip:103.88.32. XXX
linux下执行shell脚本调用sql文件,传输到远程服务器
Paper reading: deep residual learning in spiking neural networks
Tianyi cloud Hangzhou virtual machine (VPS) performance evaluation
数据保护/磁盘列阵RAID保护 IP段103.103.188.xxx
ArraysList方法
Sword finger offer question brushing record - offer 03 Duplicate numbers in array
Solve the problem that the unit test coverage of sonar will be 0
Évaluation des performances de la machine virtuelle Tianyi Cloud Hangzhou (VPS)
爬虫基础—爬虫的基本原理