c#控制台用数字6和9显示“I ❤ YOU”

来源:互联网 发布:码头仓库总店 淘宝 编辑:程序博客网 时间:2024/06/06 19:56

利用数字6和9,只高亮9,显示出“I ❤ YOU”,效果如图:



代码如下:

方法一:

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        private static string str = @"99669999996669999996699666699666999966699666699 99699999999699999999699666699669966996699666699 99669999999999999996699666699699666699699666699 99666699999999999966666999966699666699699666699 99666666999999996666666699666699666699699666699 99666666669999666666666699666669966996699666699 99666666666996666666666699666666999966669999996 ";        static void Main(string[] args)        {            Console.ForegroundColor = ConsoleColor.Cyan;            Console.WriteLine("请输入你的姓名并回车");            string input = Console.ReadLine();            bool istrue = false;            if (input == "XXX")            {                foreach (char c in str)                {                    if (c == '6')                    {                        Console.ForegroundColor = ConsoleColor.Green;                    }                    else                    {                        Console.ForegroundColor = ConsoleColor.Red;                    }                    Console.Write(c);                }                Console.WriteLine();                Console.ReadKey();            }            else            {                Console.WriteLine("您输入有误!");            }        }    }}


方法二:

  static void WriteString(String s)        {            var orginColor = Console.ForegroundColor;            for (int i = 0; i < s.Length; i++)            {                if (s[i].Equals('6'))                {                    Console.ForegroundColor = ConsoleColor.Red;                }                else                {                    Console.ForegroundColor = orginColor;                    Console.ForegroundColor = ConsoleColor.Blue;                }                Console.Write(s[i]);            }            Console.WriteLine();             Console.ReadKey();        }        static void Main()        {            WriteString(@"99669999996669999996699666699666999966699666699 99699999999699999999699666699669966996699666699 99669999999999999996699666699699666699699666699 99666699999999999966666999966699666699699666699 99666666999999996666666699666699666699699666699 99666666669999666666666699666669966996699666699 99666666666996666666666699666666999966669999996");        }


0 1
原创粉丝点击