当前位置:网站首页>用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();
}
}
边栏推荐
- 基于小波域的隐马尔可夫树模型的图像去噪方法的matlab实现代码
- How does the advanced anti DDoS server confirm which are malicious ip/ traffic? ip:103.88.32. XXX
- About file upload and download
- 类与对象
- 剑指Offer刷题记录——Offer 03. 数组中重复的数字
- PyTorch学习笔记(一)
- M simulation of UWB MIMO radar target detection based on MATLAB, considering time reversal
- 传奇游戏架设教程
- The use and differences of dictionaries, tuples and lists,
- Performance evaluation and comparison of lightweight application servers of major cloud service manufacturers, Alibaba cloud, Tencent cloud, Huawei cloud, and ucloud
猜你喜欢

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

PyTorch学习笔记(一)

Xiaodi network security - Notes (5)

m基于Lorenz混沌自同步的混沌数字保密通信系统的FPGA实现,verilog编程实现,带MATLAB混沌程序

m基于matlab的超宽带MIMO雷达对目标的检测仿真,考虑时间反转

基于simulink的转速反馈单闭环直流调速系统

SYN洪水攻击的原理,syn洪水攻击的解决办法

爬虫基础—爬虫的基本原理

Performance evaluation and comparison of Huawei cloud Kunpeng arm ECs and x86 ECS

What do you need to build a website
随机推荐
PyTorch学习日记(四)
Minecraft整合包 [GTNH]格雷科技:新视野 服务器搭建教程
Minecraft Paper 1.18.1 版开服教程,我的世界开服教程,MCSManager9面板使用教程
Dictionary, use of sets, conversion of data types
Class is coming. Roll call is needed
Xiaodi network security - Notes (4)
剑指Offer刷题记录——Offer 06.从尾到头打印链表
5G时代服务器在这里面起着什么作用?
函数与随机数
Weight matching (greedy)
Steam游戏服务器配置选择 IP
论文阅读:Deep Residual Shrinkage Networksfor Fault Diagnosis
Paper reading: deep residual learning in spiking neural networks
STEAM游戏高主频i9-12900k 搭建CS:GO服务器
闭包与装饰器
What happened to redraiment
企业或个人域名备案怎么弄
快速掌握sort命令,tr命令
Regular expression, generator, iterator
urllib库的使用