diff --git "a/\347\254\2545\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/Program.cs" "b/\347\254\2545\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/Program.cs" new file mode 100644 index 0000000000000000000000000000000000000000..839cac4e26196a5213c65c6294f7564b76249cf7 --- /dev/null +++ "b/\347\254\2545\346\254\241\344\275\234\344\270\232/\346\235\216\345\230\211\345\237\216/Program.cs" @@ -0,0 +1,135 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace ConsoleApp1 +{ + class Program + { + static void Main(string[] args) + { + //a(); + //b(); + c(); + //d(); + //f(); + } + public static void a() + { + //1、生成0-5之间的随机小数,保留两位小数(必须是2位)。 + Random random = new Random(); + for (int i = 0; i < 10; i++) + { + double a=random.NextDouble()+random.Next(6); + + Console.WriteLine(a.ToString("f2")); + } + + } + public static void b() + { + //2、生成4-7之间的随机小数,保留两位小数。 + Random random = new Random(); + for (int i = 0; i < 10; i++) + { + double a = random.Next(4,8) + random.NextDouble(); + Console.WriteLine(a.ToString("f2")); + } + } + public static void c() + { + //3、生成一个随机整型数组,长度是10,内容是1~10,数组内容不重复。 + int[] a = new int [10]; + Random random = new Random(); + + for (int i = 0; i < a.Length; i++) + { + a[i] = random.Next(1, 11); + for (int j = 0; j < i; j++) + { + if (a[i]==a[j]) + { + i--; + } + } + + } + for (int i = 0; i < a.Length; i++) + { + Console.WriteLine(a[i]); + + } + + } + public static void d() + { + //4、用户输入邮箱,请验证其合法性。 + // 1、邮箱一定需要 @符号 + + // 2、根据 @符号分为两部分,“前半部分 @ 后半部分”, + //前半部分可以数字、字母、下划线、中划线、 .(符号点)。但是.(符号点)不能 用在开头也不能用在结尾; + + // 后半部分可以数字、字母、下划线、中划线、.(符号点),且符号点是必须的,至少出现一次,但不能连续出现,且符号点不能在开头,也不能在结尾。 + //后半部分的符号点后面只能是:com、org、net、edu、mil、tv、biz、info + while (true) + { //@\w(.com|.org|.net|.edu|.mil|.tv|.biz|.info) + Console.WriteLine("请输入邮箱开头6位数的"); + string a= Console.ReadLine(); + if (Regex.IsMatch(a, @"^(\w....\w)@(\w\w)[.]{1}(com|org|net|edu|mil|tv|biz|info)$")) + { + Console.WriteLine(a); + Console.WriteLine("正确"); + } + else + { + Console.WriteLine("错误"); + } + } + + } + public static void f() + { + /*/5、用户输入手机号码,请验证其合法性。 + 手机号码规则: + 最开头+86可有可无 + 13开头第三位是 0-9 + 14开头第三位是 5或7 + 15开头第三位是 0-9不包含4 + 17开头第三位是 678中的一个 + 18开头第三位是 0-9 + 剩下的8位,都是0-9的数字。/*/ + while (true) + { + Console.WriteLine("请输入手机号码"); + string a= Console.ReadLine(); + if (Regex.IsMatch(a, @"^(13)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) + { + Console.WriteLine("正确"+"+86 "+a); + } + else if (Regex.IsMatch(a, @"^(14)(5|7)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) + { + Console.WriteLine("正确" + "+86 " + a); + } + else if (Regex.IsMatch(a, @"^(15)(0|1|2|3|5|6|7|8|9)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) + { + Console.WriteLine("正确" + "+86 " + a); + } + else if (Regex.IsMatch(a, @"^(17)(6|7|8)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) + { + Console.WriteLine("正确" + "+86 " + a); + } + else if (Regex.IsMatch(a, @"^(18)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$")) + { + Console.WriteLine("正确" + "+86 " + a); + } + else + { + Console.WriteLine("错误重新输入"); + } + } + } + } +}