//练习1:截取生日 Console.Write("请输入你的身份证号码:"); string id = Console.ReadLine(); Console.WriteLine("你的生日是:" + id.Substring(6, 4) + "年" + id.Substring(10, 2) + "月" + id.Substring(12, 2) + "日"); Console.ReadLine();
/* *练习2:判断邮箱格式是否正确 *分析: *1、有且只能有一个@ *2、不能以@开头 *3、不能以.结尾 *4、@和.不能靠在一起 *5、@之后至少有一个. */ Console.Write("请输入邮箱账号:"); string mail = Console.ReadLine(); if (mail.Contains("@")) { int aa = mail.IndexOf("@"); int bb = mail.LastIndexOf("@"); if (aa == bb) { bool a = mail.StartsWith("@"); if (!a) { string ss = mail.Substring(aa); if (ss.Contains(".")) { int dian = ss.IndexOf("."); if (dian != 1) { int hou = ss.LastIndexOf("."); if (hou != ss.Length - 1) { Console.WriteLine("输入邮箱的格式正确!"); } else { Console.WriteLine("输入有误!"); } } else { Console.WriteLine("输入有误!"); } } else { Console.WriteLine("输入有误!"); } } else { Console.WriteLine("输入有误!"); } } else { Console.WriteLine("输入有误!"); } } else { Console.WriteLine("输入有误!"); } Console.ReadLine();
//练习3:获取当前时间,增加n天后打印出是星期几 DateTime date = new DateTime(); date = DateTime.Now; DayOfWeek day=date.DayOfWeek; Console.WriteLine("当前时间为:"+ date +" "+day); Console.Write("请输入要增加的天数:"); int n=int.Parse(Console.ReadLine()); DateTime date1 = new DateTime(); date1=date.AddDays(n); DayOfWeek day1 = date1.DayOfWeek; Console.WriteLine("增加" + n + "天后,时间为:" + date1 +" "+day1); Console.ReadLine();