zoukankan      html  css  js  c++  java
  • 使用二重循环打印以下图形

    * * * * *

       * * *

      *

      *

     * * *

    * * * * *

    public class Text{

      public static void main(string[]args){

        for(        ){

          for(int k=0;k<=2-Math.abs(i);k++){

            System.our.print(" ")

          }

          for(int j=0;j<Math.abs(i)*2+1;j++){

            System.out.print("*")

          }

          System.out.println();

    }

    }

    }

    A.int i=0;i<5;i++

    B.int i=4;i<=0;i--

    C.int i=-2;i>=2;i++

    D.int i=2;i>=-2;i=i-1

    实现思路

    1.判断外层循环的横数,图形共有5横,判断ABCD选项是否都循环5次

    2.当ABCD都循环5次时,进入内层循环

    3.假设A选项成立,当i=1时带入

    for(int j=0;j<Marth.abs(i)*2+1;j++){

      System.out.print("*")

    }

    当中,最多只能输出3个*,所以B,pass掉

    4.假设B选项成立,当i=4时带入

    for(int k=0;k<=2-Marth.abs(i);k++){

      System.our.print(" ")

    }

    当中,k<=-2,条件不正确

    5.C选项条件不正确,所以排除法选D

  • 相关阅读:
    乌龟棋
    Cut the Sequence
    [NOI2001]炮兵阵地
    Fence
    环路运输
    查找并替换字符串 Find And Replace in String
    最大交换 Maximum Swap
    丑数问题 Ugly Number
    二叉树最大宽度 Maximum Width of Binary Tree
    距离为K的节点 All Nodes Distance K in Binary Tree
  • 原文地址:https://www.cnblogs.com/ainiaiwo/p/5253949.html
Copyright © 2011-2022 走看看