• <C#任务导引教程>练习一


    //1,定位显示ASCI码值为30到119的字符
    using System;
    class Program
    {
        static void Main()
        {
            int i, n = 0;
            for (i = 30; i <= 119; i++)
            {
                if (n % 10 == 0 && n > 0)
                    Console.WriteLine();
                    Console.Write("{0:D3}:{1}  ", i, (char)i);
                    n++;     
            }
            Console.WriteLine();
        }
    }

    //2,按左下方为三角形格式输出九九乘法表
    using System;
    class Program
    {
        static void Main()
        {
            int m, n;
            Console.Write("   *");
            for (m = 1; m <= 9; m++)
                Console.Write("{0,4}", m);
            Console.WriteLine();
            for (m = 1; m <= 9; m++)
            {
                Console.Write("{0,4}", m);
                for (n = 1; n <= m; n++)
                    Console.Write("{0,4}", m * n);
                Console.WriteLine();
            }
        }
    }

    //2.1,编程输出倒三角图案
    using System;
    class Program
    {
        static void Main()
        {
            int i, j, k;
            for (i = 1; i <= 4; i++)
            {
                for (j = 1; j < i; j++)
                    Console.Write(" ");
                for (k = 1; k <= 9 - 2 * i; k++)
                    Console.Write("*");
                Console.WriteLine();
            }
        }
    }

    //3,编程输出1-100的3的倍数
    using System;
    class Program
    {
        static void Main()
        {
            int i, n = 0;
            for (i = 1; i < 100; i++)
            {
                if (i % 3 != 0)
                    continue;
                if (n % 10 == 0 && n > 0)
                    Console.WriteLine();
                n++;
                Console.Write("{0,3}", i);
            }
            Console.WriteLine();
        }
    }

    //4,输入5个整数,并显示正整数,读到负整数时做出相应处理
    using System;
    class MainClass
    {
        static void Main()
        {
            int i;
            for (i = 1; i <= 5; i++)
            {
                Console.Write("请输入第{0}个数:", i);
                string x = Console.ReadLine();
                int n = int.Parse(x);
                if (n < 0)
                    break;
                Console.WriteLine("n={0}", n);
            }
            Console.WriteLine("该数是负数!");
        }
    }

    //5,输入5个整数,并显示正整数,读到负整数时做出相应处理
    using System;
    class MainClass
    {
        static void Main()
        {
            int i;
            for (i = 1; i <= 5; i++)
            {
                Console.Write("请输入第{0}个数:", i);
                string x = Console.ReadLine();
                int n = int.Parse(x);
                if (n < 0)
                    continue;
                Console.WriteLine("n={0}", n);
            }
            Console.WriteLine("该数是负数!");
        }
    }

  • 相关阅读:
    javascript高级编程笔记第五章
    关于form表单:hover没有修改表单子元素样式
    JavaScript 生成 对应的protobuf 对象
    ProtoBuf Maven 整合 用来生成对象
    NettyClient 连接 WebSocket
    Exception in thread "Thread-5" java.lang.NoSuchMethodError: io.netty.util.concurrent.SingleThreadEventExecutor异常处理
    Jsonp 使用 爬取 可直接解析页面
    OpenResty 配置SSL 同时支持http 全部转发到 https中
    Nginx(OpenResty)+Lua+Redis IP限流 10s内
    NginxUrl校验路径token+时间戳
  • 原文地址:https://www.cnblogs.com/zhangyongjian/p/3617707.html
Copyright © 2020-2023  润新知