zoukankan      html  css  js  c++  java
  • for循环练习二

    最近比较忙好几天没有更新博客了,过几天补上,博客作为我课后作业的一种形式,绝对不能落下.

    下面那个菱形排序,别人只要几分钟就想出来了,我竟然花了好几个小时.这智商,真想一头撞死算了,数学不好是不是就学不好计算机了…….各位大神什么看法,求指点

    publicclass test13 {

     

    /** 

        *
      ***
     *****
    *******
     *****
      ***
        *

     

     

    * @param args

    */

    publicstaticvoid main(String[] args){

    // TODO Auto-generated method stub

    Scanner sc=new Scanner(System.in);

    int aa=sc.nextInt();//自定义输出行数

    for(int i=1;i<=aa/2+1;i++)//上半部分换行,i为行号

    {

    for(int j=1;j<=aa/2+1-i;j++)

    {

    System.out.print(" ");

    }

    for(int k=1;k<=2*i-1;k++)

    {

    System.out.print("*");

    }

    System.out.println();

    }

    for(int l=aa/2+2;l<=aa;l++)//下半部分

    {

    for(int m=1;m<=l-aa/2-1;m++)

    {

    System.out.print(" ");

    }

    for(int n=1;n<=2*(aa/2+1)-1-2*(l-aa/2-1);n++)

    {

    System.out.print("*");

    }

    System.out.println();

    }

    publicclass test14 {

     

    /**打印 空心菱形

     @param args

    */

    publicstaticvoid main(String[] args){

    // TODO Auto-generated method stub

    Scanner sc=new Scanner(System.in);

    int aa=sc.nextInt();//自定义输出行数

    for(int i=1;i<=aa/2+1;i++)//上半部分换行,i为行号

    {

    for(int j=1;j<=aa/2+1-i;j++)

    {

    System.out.print(" ");

    }

    for(int k=1;k<=2*i-1;k++)

    {

    if(k!=1&&k!=2*i-1)

    {

    System.out.print(" ");

    }else{

     

    System.out.print("*");

    }

    }

    System.out.println();

    }

    for(int l=aa/2+2;l<=aa;l++)//下半部分

    {

    for(int m=1;m<=l-aa/2-1;m++)

    {

    System.out.print(" ");

    }

    for(int n=1;n<=2*(aa/2+1)-1-2*(l-aa/2-1);n++)

    {

    if(n!=1&&n!=2*(aa/2+1)-1-2*(l-aa/2-1))

    {

    System.out.print(" ");

    }else{

    System.out.print("*");

    }

    }

    System.out.println();

    }

  • 相关阅读:
    Http协议(一)基础知识
    Redis问题汇总
    Sql Server存储过程传递XML参数
    C# Redis
    Task的异常捕获和处理方法
    Entity Framework教程
    WebBrowser 弹窗体关闭原理
    C# 虹软SDK视频人脸识别和注册
    C#性能优化:延迟初始化Lazy
    DZ 特殊主题简单开发教程
  • 原文地址:https://www.cnblogs.com/foreverstudent/p/3060294.html
Copyright © 2011-2022 走看看