Unity3D开发-C#语言进阶篇(for循环之加密数字及九九乘法表)

class Program
    {
        static void Main(string[] args)
        {
             jiami();
            diyiti();
            dierti();
           disanti();
            disiti();
            diwuti();
            jiujiu();
            Console.ReadKey();
        }

        static void jiami()
        {
            //------------加密数字------------
            Console.WriteLine("请输入4位数");
            int shuru = Convert.ToInt32(Console.ReadLine());
            int gewei = shuru % 10;
            int shiwei = shuru / 10 % 10;
            int baiwei = shuru / 100 % 10;
            int qianwei = shuru / 1000;
            string jiami = "";

            gewei = (gewei + 5) % 10;
            shiwei = (shiwei + 5) % 10;
            baiwei = (baiwei + 5) % 10;
            qianwei = (qianwei + 5) % 10;
            jiami =""+gewei + shiwei + baiwei + qianwei;
            Console.WriteLine("加密数字后为:{0}",jiami);
            //  1234 6789 9876
            Console.WriteLine("\n");
        }

        static void diyiti()
        {
            //--------第一题--------
            for (int i = 0; i < 3; i++)
            {

                for (int j = 0; j < 3; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
            Console.WriteLine("\n");
        }

        static void dierti()
        {
            //--------第二题--------
            for (int i = 1; i <= 3; i++)
            {

                for (int j = 0; j < i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
            Console.WriteLine("\n");
        }

        static void disanti()
        {
            //--------第三题--------
            for (int i = 0; i <= 3; i++)
            {

                for (int j = 3; j >i; j--)
                {
                    Console.Write("*");
                }
                Console.WriteLine();

            }
            Console.WriteLine("\n");
        }

        static void disiti()
        {
            //--------第四题--------
            for (int i = 0; i < 3; i++)
            {
                for (int k = 2; k > i; k--)
                {
                    Console.Write(" ");
                }

                for (int j = 0; j <= i; j++)
                {
                    Console.Write("*");
                }
                Console.WriteLine();
            }
            Console.WriteLine("\n");
        }


              static void diwuti()
        {
            //--------第五题--------
            for (int i=0;i<3;i++){
                for (int k = 0; k < i; k++)
                {
                    Console.Write(" ");
                }

                for(int j=3;j>i;j--){
                    Console.Write("*");
                }
                Console.WriteLine();
            
            }
            Console.WriteLine("\n");
        }


        static void jiujiu()
        {
            
        for(int i=1;i<=9;i++){
            for (int j = i; j <= 9; j++)
            {
                if (i <= 4 && j < 3 && j > 1)
                {
                    Console.Write("{0}x{1}={2}  ", j, i, i * j);
                }
                else
                {
                    Console.Write("{0}x{1}={2} ", j, i, i * j);
                }

            }

            Console.WriteLine("\n");
        }

       
        }
    }

你可能感兴趣的:(Unity3D开发-C#语言进阶篇(for循环之加密数字及九九乘法表))