C#基礎第二天-作業答案-九九乘法表-列印星星

來源:互聯網
上載者:User

標籤:for   nbsp   str   九九乘法表   換行   console   parse   bsp   convert   

題一:九九乘法表的答案                //正三角            for (int i = 1; i < 10; i++)            {                for (int j = 1; j <= i; j++)                {                    Console.Write("{0}*{1}={2} ", j, i, i * j);                }                Console.WriteLine();            }            Console.ReadLine();            //倒三角            for (int i = 9; i >= 1; i--)            {                for (int j = i; j >= 1; j--)                {                    Console.Write("{0}*{1}={2} ", i, j, i * j);  //不換行                }                Console.WriteLine(); //換行            }            Console.ReadLine();              反倒三角            string sd = string.Empty;            for (int i = 9; i >= 1; i--)            {                for (int j = i; j >= 1; j--)                {                    string k = "  ";                    if (j * i > 9)                    {                        k = " ";                    }                    Console.Write("{0}*{1}={2}{3}", j, i, i * j, k);                }                Console.WriteLine();                sd += "       ";                Console.Write(sd);            }            Console.ReadLine();題二:            //星星圖1            Console.WriteLine("請輸入您想看到的星星行數");            int num = Convert.ToInt32(Console.ReadLine());            for (int hang = 1; hang <= num; hang++)            {                string k = String.Empty;                string x = String.Empty;                for (int kong = 1; kong <= num - hang; kong++)                {                    k += " ";                }                for (int xing = 1; xing <= hang; xing++)                {                    x += "* ";                }                Console.WriteLine(k + x + k);            }            Console.ReadLine();            //星星圖(倒三角星星)            Console.WriteLine("請輸入您想看到的星星行數");            int num = Convert.ToInt32(Console.ReadLine());            for (int hang = 1; hang <= num; hang++)            {                string k = String.Empty;                string x = String.Empty;                for (int kong = 1; kong <= hang - 1; kong++)                {                    k += " ";                }                for (int xing = 1; xing <= num - hang + 1; xing++)                {                    x += "* ";                }                Console.WriteLine(k + x + k);            }            Console.ReadLine();            ////星星圖四            Console.WriteLine("請輸入您想看到的星星行數");            int num = Convert.ToInt32(Console.ReadLine());            int gg = num * 2;            for (int hang = 1; hang <= num; hang++)            {                string k = String.Empty;                string x = String.Empty;                for (int kong = 1; kong <= gg - 2 * hang; kong++)                {                    k += " ";                }                for (int xing = 1; xing <= hang; xing++)                {                    x += "* ";                }                Console.WriteLine(k + x);            }            Console.ReadLine();            //星星圖(倒三角*)            Console.WriteLine("請輸入您想看到的星星行數");            int num = Convert.ToInt32(Console.ReadLine());            int gg = num * 2;            for (int hang = 1; hang <= num; hang++)            {                string k = String.Empty;                string x = String.Empty;                for (int kong = 1; kong <= 2 * (hang - 1); kong++)                {                    k += " ";                }                for (int xing = 1; xing <= num - hang + 1; xing++)                {                    x += "* ";                }                Console.WriteLine(k + x);            }            Console.ReadLine();           //星星圖(最終效果菱形)            int a = int.Parse(Console.ReadLine());            for (int i = 0; i <= a; i++)            {                string k = String.Empty;                string x = String.Empty;                for (int s = 0; s < a - i + 1; s++)                {                    k += " ";                }                for (int d = 0; d < 2 * i - 1; d++)                {                    x += "*";                }                Console.WriteLine(k + x + k);            }            for (int i = a - 1; i > 0; i--)            {                string k = String.Empty;                string x = String.Empty;                for (int s = 0; s < a - i + 1; s++)                {                    k += " ";                }                for (int d = 0; d < 2 * i - 1; d++)                {                    x += "*";                }                Console.WriteLine(k + x + k);            }            Console.ReadLine();          //星星圖(顯示 圖四效果/圖五效果)最終顯示圖六效果          for (int i = 1; i <= 4; i++)            {                for (int j = 1; j <= 4 - i; j++)                {                    Console.Write(" ");                }                for (int k = 1; k <= i; k++)                {                    Console.Write("*");                }                Console.WriteLine("");            }            for (int i = 4; i >= 1; i--)            {                for (int j = 1; j <= 4 - i; j++)                {                    Console.Write(" ");                }                for (int k = 1; k <= i; k++)                {                    Console.Write("*");                }                Console.WriteLine("");            }            Console.ReadKey();

 

C#基礎第二天-作業答案-九九乘法表-列印星星

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.