• 几个循环小练习


    1.十八个年龄

    Console.Write("请输入您的名字:");
    string a = Console.ReadLine();
    for (int i = 1; i <= 18;i++ )
    {
    Console.Write("我叫"+a+","+"我今年"+i+"岁了。");
    switch (i)
    {
    case 6: Console.Write("我上小学了!"); break;
    case 11: Console.Write("我上初中了!"); break;
    case 15: Console.Write("我上高中了!"); break;
    case 18: Console.Write("我成年了!考上了北大!"); break;
    }
    Console.WriteLine();
    }
    Console.ReadLine();

    2.99乘法表

    for (int i = 1; i <= 9; i++)
    {
    for (int l = 1; l <= i; l++)
    {
    int a = l * i;
    Console.Write(l + "*" + i + "=" + a + " ");
    }
    Console.WriteLine();
    }

    3.各种三角形

    //三角形1
    for (int i = 1; i <= 5; i++)
    {
    for (int l = 1; l <= i; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }
    //三角形2
    for (int i = 1; i <= 5; i++)
    {
    for (int l = i; l <= 5; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }
    //三角形3
    for (int i = 1; i <= 5; i++)
    {
    for (int l = i; l < 5; l++)
    {
    Console.Write(" ");
    }
    for (int l = 1; l <= i; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }
    //三角形4
    for (int i = 1; i <= 5; i++)
    {
    for (int l = 1; l < i; l++)
    {
    Console.Write(" ");
    }
    for (int l = i; l <= 5; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }
    //三角形5
    for (int i = 1; i <= 5; i++)
    {
    for (int l = i; l < 5; l++)
    {
    Console.Write(" ");
    }
    for (int l = 1; l <= i; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }

     4.菱形

    Console.Write("请输入一个数字");
    int a = int.Parse(Console.ReadLine());
    for (int i = 1; i <= a; i++)
    {
    for (int l = i; l < a; l++)
    {
    Console.Write(" ");
    }
    for (int l = 1; l <= i; l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }
    for (int i = 1; i <= a; i++)
    {
    for (int l = 0; l < i; l++)
    {
    Console.Write(" ");
    }
    for (int l = i; l <= (a - 1); l++)
    {
    Console.Write("★");
    }
    Console.WriteLine();
    }

  • 相关阅读:
    诡异的楼梯 HDU1180
    selenium的那些命令:
    权限管理:
    图片裁剪:
    2-15 showapiRequest解决图片验证码识别.py
    2-14 使用pytesseract识别图片中得问题.py
    使用C#开发ActiveX控件 11
    Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
    Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
    Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
  • 原文地址:https://www.cnblogs.com/mazhijie/p/5456547.html
Copyright © 2020-2023  润新知