C#基础第二天-作业答案-九九乘法表-打印星星

题一:九九乘法表的答案    


            //正三角
            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#基础总结之八面向对象知识点总结-继承与多态-接口-http://www.cnblogs.com/spring_wang/p/6113531.html

C#基础总结之七面向对象知识点总结1http://www.cnblogs.com/spring_wang/p/6113526.html

C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习http://www.cnblogs.com/spring_wang/p/6113520.html

C#基础总结之五Dictionary<string, string[]>和while循环http://www.cnblogs.com/spring_wang/p/6113514.html

C#基础总结之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html

C#基础总结之三循环控制-for-数组-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html

C#基础总结之二循环控制-运算符http://www.cnblogs.com/spring_wang/p/6113484.html

C#基础总结之一变量常量-if嵌套语句-witch结构-类型转换http://www.cnblogs.com/spring_wang/p/6113476.html

C#基础课程之六(临时表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html

C#基础课程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html

C#基础课程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html

C#基础课程之三循环语句http://www.cnblogs.com/spring_wang/p/6113383.html

C#基础课程之二变量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html

C#基础课程之一注释和控制台、一些常识http://www.cnblogs.com/spring_wang/p/6113361.html

C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html

C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html

C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113274.html

C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113258.html

C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113232.html

C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113224.html

C#基础第六天-作业-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113028.html

C#基础第六天-作业答案-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113033.html

C#基础第五天-作业答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html

C#基础第五天-作业-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html

C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113005.html

C#基础第四天-作业-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113000.html

C#基础第三天-作业答案-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112888.html

C#基础第三天-作业-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112885.html

C#基础第二天-作业答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html

C#基础第二天-作业-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html

C#基础第一天-作业答案http://www.cnblogs.com/spring_wang/p/6112872.html

C#基础第一天-作业http://www.cnblogs.com/spring_wang/p/6112867.html

C#-string.Format对C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html

posted @ 2016-11-29 11:32  王春天  阅读(2538)  评论(0编辑  收藏  举报
云推荐