栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA菱形(空心or实心)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA菱形(空心or实心)

空心菱形

7行菱形
public class lingxing{

  1. public static void main(String[] args){
  2. //上部分;
  3. for(int a=1; a<=4; a++){
  4. for(int b=1;b<=4-a;b++){
  5. System.out.print(‘’ ‘’);}
  6. for(int c=1;c<=2*a-1;c++){
  7. if(c= =1 || c= =2*a-1){
  8. System.out.print(‘’ * ‘’);}
  9. else{System.out.print(‘’ ‘’);}}
  10. System.out.println();}
  11. //下部分;
  12. for(int a=1;a<=3;a++){
  13. for(int b=1;b<=a;b++){
  14. System.out.print(‘’ ‘’);}
  15. for(int c=1;c<=7-2*a;c++){
  16. if(c= =1 || c= =7-2*a){
  17. System.out.print(‘’ * ‘’);}
  18. else{System.out.print(‘’ ‘’);}}
  19. System.out.println();}
实心
  1. for(int a=1;a<=4;a++){
  2. for(int b=1;b<=4-a;b++){
  3. System.out.print(‘’ ‘’);}
  4. for(int c=1;c<=2*a-1;c++){
  5. System.out.print(‘’ * ‘’);}
  6. System.out.println();}
  7. for(int a=1;a<=3;a++){
  8. for(int b=1;b<=a;b++){
  9. System.out.print(‘’ ‘’);}
  10. for(int c=1;c<=7-2*a;c++){
  11. System.out.print(‘’ * ‘’);}
  12. System.out.println();} }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/306934.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号