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();

    }

  • 相关阅读:
    MVC对session或cookie保存的值在js中做处理
    JQuery判断是否是移动端
    C# Guid 和 JQuery Guid
    JQuery Cookie操作
    DES置换表加密
    RSA的基础运算
    minikatz免杀之msf加载bin文件
    minikatz免杀之Out-EncryptedScript加密
    vue 多选框
    小程序加载更多,上拉刷新
  • 原文地址:https://www.cnblogs.com/foreverstudent/p/3060294.html
Copyright © 2011-2022 走看看