摘要: using System;class Class1{ static void Main() { Console.WriteLine("请输入第一个数:"); int a=Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入第二个数:"); int b=Convert.ToInt32(Console.ReadLine()); if(a>b) { int temp; temp=b; b=a; a=temp; } i... 阅读全文
posted @ 2011-09-13 21:38 BeFlyingWind 阅读(8413) 评论(0) 推荐(0)
摘要: C#中Trim()、TrimStart()、TrimEnd()的错误认识 这三个方法用于删除字符串头尾出现的某些字符。Trim()删除字符串头部及尾部出现的空格,删除的过程为从外到内,直到碰到一个非空格的字符为止,所以不管前后有多少个连续的空格都会被删除掉。TrimStart()只删除字符串的头部的空格。TrimEnd()只删除字符串尾部的空格。 如果这三个函数带上字符型数组的参数,则是删除字符型数组中出现的任意字符。如Trim("abcd".ToCharArray())就是删除字符串头部及尾部出现的a或b或c或d字符,删除的过程直到碰到一个既不是a也不是b也不是c也不是d 阅读全文
posted @ 2011-09-12 10:55 BeFlyingWind 阅读(518) 评论(0) 推荐(0)
摘要: using System;class Class1{ static void Main() { float s=1; int sum=1; Console.WriteLine("请输入一个数:"); int n=Convert.ToInt32(Console.ReadLine()); for(int i=2,j=1;i<n;i++) { j=j*i; sum=sum+(float)1/j;//此处float强制类型转换,使精度更高! } Console... 阅读全文
posted @ 2011-09-11 23:47 BeFlyingWind 阅读(164) 评论(0) 推荐(0)
摘要: using System;class Class1{ static void Main() { Console.WriteLine("请输入一个整数:"); int x=Convert.ToInt32(Console.ReadLine()); int s=0; while(x!=0) { s=s*10+x%10; /*这是倒序的关键步骤*/ x=x/10; } Console.WriteLine("倒序后:"); Console.Wri... 阅读全文
posted @ 2011-09-11 23:23 BeFlyingWind 阅读(2980) 评论(0) 推荐(0)