zoukankan      html  css  js  c++  java
  • 大数据学习--day05(嵌套循环、方法、递归)

    嵌套循环、方法、递归

    图形打印

     public static void main(String[]arg)
        {
            /**
            *     *
             *   *
              * *
             */
           // 3 2 1 0
           //   1 3 5
            for(int i=0;i<3;i++)
            {
                //空格 递增空格
                for (int j=0;j<i; j++)
                {
                    System.out.print(" ");
                }
                System.out.print("*");
    
                //空格 递减  5  3  1
                for (int j=3;j>i; j--)
                {
                    if(j==3)
                        System.out.print(" ");
                    else
                        System.out.print("  ");
                }
                System.out.print("*");
                System.out.println(" ");
    
            }
            /**
                   *
                  * *
                 *   *
                *     *
             */
            for(int i=0;i<4;i++)
            {
                //空格 递减空格 3 2 1 0
                for (int j=0;j<3-i; j++)
                {
                    System.out.print(" ");
                }
                System.out.print("*");
    
                //空格 递增 1 3 5
                for (int j=4;j>4-i; j--)
                {
                    if(j==4)
                        System.out.print(" ");
                    else
                        System.out.print("  ");
                }
                if(i!=0)
                    System.out.print("*");
                System.out.println(" ");
    
            }
        }

    public static void main(String[]arg)
        {
            /**
              *
             * *
            *   *
           *     *
             */
            for(int i=0;i<4;i++)
            {
                //空格 递减 4 3 2 1
                for(int j=0;j<4-i;j++)
                {
                    System.out.print(" ");
                }
                System.out.print("*");
                //空格 递增 1 3 5
                for(int j=0;j<i;j++)
                {
                    if(j==0)
                        System.out.print(" ");
                    else
                        System.out.print("  ");
                }
                if(i!=0)
                    System.out.print("*");
                System.out.println(" ");
            }
            /**
             *   *
              * *
               *
             */
            for(int i=0;i<3;i++)
            {
                //空格 递增 1 2 3
                for(int j=0;j<=i+1;j++)
                {
                    System.out.print(" ");
                }
                System.out.print("*");
                //空格 递减 3 1 0
                for(int j=0;j<2-i;j++)
                {
                    if(j==0)
                        System.out.print(" ");
                    else
                        System.out.print("  ");
                }
                if(i!=2)
                    System.out.print("*");
                System.out.println(" ");
            }
        }

    百钱买百鸡

     public static void main(String[] arg)
        {
            /**
             百钱买百鸡
             100块 要买100只鸡
             公鸡5块 母鸡3块 小鸡1块3个
             100块花完  买了100个鸡
             求 有几种买法  分别买了多少只 公鸡母鸡小鸡
             使用循环来做
             */
            int gcount=100/5;
            int mcount=100/3;
    
            for(int i=0;i<=gcount;i++)
            {
                for(int j=0;j<=mcount;j++)
                {
                    int xiaoji=100-i-j;
                    if((i*5+j*3+xiaoji/3==100)&&xiaoji%3==0)
                    System.out.println("公鸡 "+i+" 母鸡 "+j+" 小鸡"+(100-i-j));
                }
            }
        }

    循环关键字同c#,但是外层跳出循环用一个标签写在前面:

    方法用法同c#

    递归

  • 相关阅读:
    python爬虫专栏学习
    Scrapy学习笔记
    《The Python Standard Library》——http模块阅读笔记2
    《The Python Standard Library》——http模块阅读笔记1
    《The Python Tutorial》——Errors and Exceptions 阅读笔记
    web服务器架构演化及所其技术知识体系(分布式的由来)
    django学习笔记——搭建博客网站
    《计算机系统要素》学习笔记
    python查看模块版本及所在文件夹
    网络编程---笔记2
  • 原文地址:https://www.cnblogs.com/symkmk123/p/9648806.html
Copyright © 2011-2022 走看看