zoukankan      html  css  js  c++  java
  • 5.4穷举,迭代

    1.namespace 三角形1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //循环打印行
                for (int i = 1
                    ; i < 6; i++)
                {
                    string a = "";//内容
                    //循环填充每行的内容
                    for (int j = 1; j <= i; j++)
                    {
                        a += "";
                    }
                    Console.WriteLine(a);
                }
    
                Console.ReadLine();
            }
        }
    }
    2.namespace 三角形2
    {
        class Program
        {
            static void Main(string[] args)
            {
                for (int i = 1; i < 6; i++)
                {
                    string a = "";
                    for (int j = 5; j >= i; j--)
                    {
                        a += "";
                    }
                    Console.WriteLine(a);
                }
    
                Console.ReadLine();
            }
        }
    }
    3.namespace 三角形3
    {
        class Program
        {
            static void Main(string[] args)
            {
                for (int i = 1; i < 6; i++)
                {
                    //内容拼接
                    string a = "";
                    string b = "";
                    for (int j = 5; j > i; j--)
                    {
                        a += "  ";
                    }
    
                    for (int k = 1; k <= i; k++)
                    {
                        b += "";
                    }
    
                    Console.WriteLine(a + b);
                }
    
                Console.ReadLine();
    4.amespace 方形
    {
        class Program
        {
            static void Main(string[] args)
            {
                //打印方形,每行打印10个“A”,打印10行,
                //使用循环嵌套,不允许定义内容为“AAAAAAAAAA”的变量;
    
                for (int i = 0; i < 10; i++)
                {
                    string a = "";
                    for (int j = 0; j < 10; j++)
                    {
                        a += "A";
                    }
                    Console.WriteLine(a);
                }
    
                Console.ReadLine();
            }
        }
    }
    5.namespace 去逗号
    {
        class Program
        {
            static void Main(string[] args)
            {
                //打印1-100所有的数,并在100的后面不允许出现逗号
    
                for (int i = 1; i <= 100; i++)
                {
                    if (i < 100)
                    {
                        Console.Write(i + ",");
                    }
                    else
                    {
                        Console.Write(i);
                    }
                }
    
                Console.ReadLine();
            }
        }
    }
    //6.、用户输入姓名
                Console.Write("请输入您的姓名:");
                string name = Console.ReadLine();
    
                //2、循环打印年龄
                for (int i = 1; i < 19; i++)
                {
                    //3、打印年龄的过程中增加判断
                    if (i == 6)
                    {
                        Console.WriteLine("我叫" + name + ",我今年" + i + "岁了,我上小学了!");
                    }
                    else if (i == 11)
                    {
                        Console.WriteLine("我叫" + name + ",我今年" + i + "岁了,我上初中了!");
                    }
                    else if (i == 15)
                    {
                        Console.WriteLine("我叫" + name + ",我今年" + i + "岁了,我上高中了!");
                    }
                    else if (i == 18)
                    {
                        Console.WriteLine("我叫" + name + ",我今年" + i + "岁了,我上大学了!我成年了!");
                    }
                    else
                    {
                        Console.WriteLine("我叫" + name + ",我今年" + i + "岁了!");
                    }
                }
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    host配置
    查看浏览器内核以及版本信息
    优化你的数据库索引
    密集索引和稀疏索引的区别
    Interview
    hadoop启动后,jps命令后发现nodename启动失败,检查日志报错:FSNamesystem initialization failed
    hadoop学习之hadoop完全分布式集群安装
    VMWare虚拟机下为Ubuntu 配置静态IP(NAT方式)ping通主机
    虚拟机突然无法使用NAT模式上网
    hadoop-0.20.2 & hbase-0.90.1 集群启动错误“org.apache.hadoop.ipc.RPC$VersionMismatch: Protocol org.apache.hadoop.hdfs.protocol.ClientP
  • 原文地址:https://www.cnblogs.com/suiyuejinghao123/p/5460723.html
Copyright © 2011-2022 走看看