更多.NET全套金典教材: 点击进入
//Random随机数 Random r = new Random(); while (true) { int i = r.Next(1, 7); Console.WriteLine(i); Console.ReadKey(); } //指定分隔符数组,返回不带空格符的字符串 string str = "my name is lei"; char[] a = { ' ' }; string[] b = str.Split(a,StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < b.Length; i++) { Console.WriteLine(b[i]); } Console.ReadKey(); //倒序输出 Console.WriteLine("请输入字符串"); string a = Console.ReadLine(); string[] d = a.Split(' '); for (int i = d.Length - 1; i >= 0;i-- ) { Console.Write(d[i]+" "); } Console.ReadKey(); //忽略大小写 string a = "a"; string b = "A"; if (a.Equals(b,StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("一样的"); } else { Console.WriteLine("不一样"); } Console.ReadKey(); //字符替换 string a = "2008-11-12"; string[] b = a.Split('-'); Console.WriteLine("{0}年{1}月{2}日", b); Console.ReadKey(); //九九乘法表 for (int i = 1; i <= 9;i++ ) { for (int j = 1; j <= i;j++ ) { Console.Write("{0}X{1}={2:00} ",i,j,i*j); } Console.WriteLine(); } Console.ReadKey(); //判断字符串内是否有指定的子字符串 string[] strc = { "xxoo", "TMD", "和谐" }; string a = Console.ReadLine(); int i; for (i = 0; i < a.Length; i++) { if (a.Contains(strc[i])) { break; } } if (i < a.Length) { Console.WriteLine("有非法字符"); } else { Console.WriteLine("合法"); } //水仙花规则 //int i = 1 * 1 * 1 + 5 * 5 * 5+3 * 3 * 3; //求100_999的水仙花数 for (int i = 100; i <= 999;i++ ) { //把个 十 百 分离出来 int ge=i%10; int shi=i/10%10; int bai=i/100; //按照水仙花数规则判断 if(i==ge*ge*ge+shi*shi*shi+bai*bai*bai ) { Console.WriteLine(i); } } Console.ReadKey(); // 求1_100直接的偶数和 int sum = 0; for (int i = 1; i <= 100;i++ ) { //如果i能被2整除说明这个数是偶数 if(i%2==0) { sum += i; Console.WriteLine(i); } } Console.WriteLine(sum); Console.ReadKey(); }
更多.NET全套金典教材: 点击进入
作者:pengqinggui 发表于2013-3-14 7:19:27 原文链接
阅读:67 评论:0 查看评论