//任意输入星期几的一个字母来判断一下是星期几,如不能判断,则再继续输入下一个字母,如再不能,
//再输入下一个字母,直到能判断出为止,并统计到能判断时输入的字母的个数。<pre name="code" class="csharp">using System; using System.Collections.Generic; using System.Linq; using System.Text; //任意输入星期几的一个字母来判断一下是星期几,如不能判断,则再继续输入下一个字母,如再不能, //再输入下一个字母,直到能判断出为止,并统计到能判断时输入的字母的个数 namespace ConsoleApplication1 { class Program { static void Main(string[] args) { char[] week1 = new char[10];//字符数组 int i = 0; Console.WriteLine("此程序只需输入一个或者两个字母就可判断是星期几"); Console.Write("请输入第一个大写字母:"); week1[i] = Convert.ToChar(Console.ReadLine()); switch (week1[i]) { case 'M': Console.Write("Monday\n"); break; case 'W': Console.Write("Wednesday\n"); break; case 'F': Console.Write("Friday\n"); break; case 'S': Console.Write("请输入第二个小写字母:"); week1[i + 1] = Convert.ToChar(Console.ReadLine()); if (week1[i + 1] == 'a') Console.Write("Saturday\n"); else if (week1[i + 1] == 'u') Console.Write("Sunday\n"); else Console.Write("没有答案\n"); break; case 'T': Console.Write("请输入第二个小写字母:"); week1[i + 1] = Convert.ToChar(Console.ReadLine()); if (week1[i + 1] == 'u') Console.Write("Tuesday\n"); else if (week1[i + 1] == 'h') Console.Write("Thursday\n"); else Console.Write("没有答案\n"); break; default: Console.Write("没有答案\n"); break; } Console.Read(); } } }
原文地址:http://blog.csdn.net/u012110719/article/details/40461367