标签:line private res 反转字符串 练习 ram blog -- param
1 class Program 2 { 3 /// <summary> 4 /// 反转字符串 5 /// </summary> 6 /// <param name="strOrignial">原字符串</param> 7 /// <returns>反转之后的字符串</returns> 8 private string RverseString(string strOrignial) 9 { 10 string strResult = null; 11 for (int i = strOrignial.Length-1; i >= 0; i--) 12 { 13 string strTemp = strOrignial.Substring(i, 1); 14 strResult = strResult + strTemp;//字符串累加 15 } 16 return strResult; 17 } 18 //判断是否是回文字符串(如:rotor) 19 private void Text() 20 { 21 string strOrstr = "rotor"; 22 string strRverseResult = RverseString(strOrstr); 23 if (strRverseResult==strOrstr) 24 { 25 Console.WriteLine("是回文字符串"); 26 } 27 else 28 { 29 Console.WriteLine("不是回文字符串"); 30 } 31 } 32 static void Main(string[] args) 33 { 34 Program p = new Program(); 35 p.Text(); 36 Console.ReadKey(); 37 } 38 }
1 class Program 2 { 3 /// <summary> 4 /// 反转字符串 5 /// </summary> 6 /// <param name="strOrignial">原字符串</param> 7 /// <returns>反转之后的字符串</returns> 8 private string RverseString(string strOrignial) 9 { 10 string strResult = null; 11 for (int i = strOrignial.Length-1; i >= 0; i--) 12 { 13 string strTemp = strOrignial.Substring(i, 1); 14 strResult = strResult + strTemp;//字符串累加 15 } 16 return strResult; 17 } 18 //判断是否是回文字符串(如:rotor) 19 private bool Text( string strOrstr) 20 { 21 string strRverseResult = RverseString(strOrstr); 22 if (strRverseResult==strOrstr) 23 { 24 return true; 25 } 26 else 27 { 28 return false; 29 } 30 } 31 //输出1-256的所有回文字符串 32 private void Text1() 33 { 34 for (int i = 1; i < 257; i++) 35 { 36 //判断i是否为回文字符串 37 bool bb= Text(i.ToString()); 38 if (bb) 39 { 40 Console.WriteLine(i); 41 } 42 } 43 } 44 static void Main(string[] args) 45 { 46 Program p = new Program(); 47 p.Text1(); 48 Console.ReadKey(); 49 } 50 }
标签:line private res 反转字符串 练习 ram blog -- param
原文地址:http://www.cnblogs.com/yx-xiansheng/p/7629495.html