From 802679de0d0c063fcab363e0f6ad8d0a85c12ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E5=BF=A7?= <2486779710@qq.com> Date: Mon, 31 May 2021 11:35:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=98=E9=BE=99=E5=86=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Program.cs" | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 "\347\254\2545\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" diff --git "a/\347\254\2545\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" "b/\347\254\2545\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" new file mode 100644 index 0000000..7af2cd0 --- /dev/null +++ "b/\347\254\2545\346\254\241\344\275\234\344\270\232/\345\210\230\351\276\231\345\206\260/Program.cs" @@ -0,0 +1,120 @@ +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) + { + //1、生成0-5之间的随机小数,保留两位小数(必须是2位)。 + Random ran = new Random(); + Console.WriteLine("------------第一题----------------"); + for (int i = 0; i < 10; i++) + { + double d = ran.NextDouble() * 5; + Console.WriteLine(d.ToString("f2")); + } + Console.WriteLine("------------第二题----------------"); + // 2、生成4 - 7之间的随机小数,保留两位小数 + for (int i = 0; i < 10; i++) + { + double d = 4 + ran.NextDouble() * (7 - 4); //min+......(max-min) + Console.WriteLine(d.ToString("f2")); + + } + Console.WriteLine("------------第三题----------------"); + //3、生成一个随机整型数组,长度是10,内容是1~10,数组内容不重复。 + + Random a = new Random(); + int[] arr = new int[10]; + for (int i = 0; i < arr.Length; i++) + { + int c = a.Next(1, 11); + arr[i] = c; + for (int j = 0; j < i; j++) + { + if (arr[i] == arr[j]) + { + i--; + } + } + } + for (int i = 0; i < arr.Length; i++) + { + Console.Write(arr[i] + " "); + } + Console.WriteLine(); + Console.WriteLine("------------第四题----------------"); + // 4、用户输入邮箱,请验证其合法性。 + // 1、邮箱一定需要 @符号 + // 2、根据 @符号分为两部分,“前半部分 @ 后半部分”, + // 前半部分可以数字、字母、下划线、中划线、 .(符号点)。但是.(符号点)不能 用在开头也不能用在结尾; + // 后半部分可以数字、字母、下划线、中划线、.(符号点),且符号点是必须的,至少出现一次,但不能连续出现,且符号点不能在开头,也不能在结尾。 + // 后半部分的符号点后面只能是:com、org、net、edu、mil、tv、biz、info + + //while (true) + //{ + // Console.WriteLine("请输入邮箱:"); + // string str = Console.ReadLine(); + // if (Regex.IsMatch(str, @"^(\w+)(\.*)(\w+)@(\w+)(\.)(com|org|net|edu|mil|tv|biz|info)$")) + // { + // Console.WriteLine(str); + // } + // else + // { + + // Console.WriteLine("格式有误"); + + // } + //} + Console.WriteLine("------------第五题----------------"); + // 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 tel = Console.ReadLine(); + if (Regex.IsMatch(tel, @"^(\+86)?(13\d{1}|14[5-7]{1}|15[0-3|5-9]{1}|17[6-8]{1}|18\d{1})(\d{8})$")) + { + Console.Write(tel); + } + else + { + Console.WriteLine("输入有误"); + } + Console.WriteLine(); + } + + + + + + + + } + + + + + + + + + + } +} + -- Gitee