java输出空心菱形
2024-10-09 05:00:59
package com.zsh; import java.util.Scanner; public class Test08 { public static void main(String[] args) { System.out.println("请输入大于3的奇数!!"); Scanner reader=new Scanner(System.in); int i;//定义行 int j;//定义列(循环空格) int a;//定义列(循环*) int b=reader.nextInt();//取得命令行中的数据(显示行数) //循环前(b/2+1)行 for(i=1;i<=b/2+1;i++){ if(i==1){ for(j=1;j<=(b-(2*i-1))/2;j++){ System.out.print(" "); } System.out.println(" *"); } else{ //循环空格 for(j=1;j<=(b-(2*i-1))/2;j++){ System.out.print(" "); } System.out.print(" *"); //循环* for(a=1;a<=2*i-3;a++){ System.out.print(" "); } System.out.println(" *"); } } //循环后(b/2)行 for(i=b/2;i>=1;i--){ if(i==1){ //循环空格 for(j=1;j<=(b-(2*i-1))/2;j++){ System.out.print(" "); } System.out.println(" *"); } else{ //循环空格 for(j=1;j<=(b-(2*i-1))/2;j++){ System.out.print(" "); } System.out.print(" *"); //循环* for(a=1;a<=2*i-3;a++){ System.out.print(" "); } System.out.println(" *"); } } } }
最新文章
- C# 单例模式
- ASP.NET MVC使用Bootstrap系统(2)——使用Bootstrap CSS和HTML元素
- Position和anchorPoint
- [51单片机] EEPROM 24c02 [I2C代码封装-保存实现流水灯]
- 用户管理 之 Linux 用户(User)查询篇
- Asp.net Json 解析 与 直接用ip访问返回josn
- SQL查询性能分析之(not in)、(and not)、()、(!=)性能比较
- [Gauss]POJ3185 The Water Bowls
- codevs4189字典(字典树)
- Roads in Berland(图论)
- android中利用view画出一条竖线
- 【转】如何在CentOS/RHEL中安装基于Web的监控系统 linux-das
- Golang适合高并发场景的原因分析
- ArcGIS Pro开发Web3D应用(2)——地图分屏对比(多屏对比)思路
- MySQL+MGR 单主模式和多主模式的集群环境 - 部署手册 (Centos7.5)
- ArcGIS 中UniqueValueRenderer和SimpleRenderer的异同点
- python函数后面有多个括号怎么理解?
- 微信小程序的同步操作
- Edit Distance问题在两种编程范式下的求解
- SqlServer行转列(PIVOT),列转行(UNPIVOT)总结