将字符串倒序
2014-09-28 22:51
260 查看
.继续在该类中编写一下方法,名称为Reconvert,参数一个,但可以是字符串、整数、单精度、双精度,方法功能返回 参数的逆序。如Reconvert(6221982)返回值为2891226。 提示:将string转换为Char char[] c=strS.ToCharArray() using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class MyClass { string m; char n; public MyClass() { } public MyClass(string m1,char n1) { m=m1; n=n1; } public int CountChar() { int x = 0; char[] a = m.ToCharArray(); for (int i = 0; i < m.Length; i++) { if (a[i] == n) x++; } return x; } public void Reconvert(string x) { char[] b = x.ToCharArray(); for (int i = 0; i < x.Length; i++) { Console.WriteLine(b[x.Length - i - 1]); } } ~ MyClass() { } } class Program { static void Main(string[] args) { int s; MyClass mc = new MyClass("063353222", '2'); s= mc.CountChar(); Console.WriteLine("2出现的次数为:"+s); MyClass mc2 = new MyClass("akfbriafsaa", 'a'); s = mc2.CountChar(); Console.WriteLine( "s出现的次数为:" + s); Console.WriteLine("abcdefg的倒序:"); mc2.Reconvert("abcdefg"); Console.ReadLine(); } } }
相关文章推荐
- 几种字符串倒序输出
- 字符串倒序反转程序
- 字符串倒序输出的两个写法
- 逆序字符串或以空格为分隔符分别倒序
- 字符串倒序输出 2011.04.07
- 字符串的倒序n种方法
- 将一个字符串倒序,如“abcd”倒序后变为“dcba”
- php字符串倒序显示
- C#中倒序输出字符串的方法示例
- 设一个字符串数组并为其输入值,当输入为“-1”时,结束输入,并倒序输出已输入的字符串。
- 杂记之C语言之位倒序和字符串倒序
- 利用递归实现对输入字符串的倒序输出
- 编写一个程序,实现字符串大小写的转换并倒序输出
- 字符串倒序反转程序
- JAVA String字符串倒序
- 将字符串中的字母倒序,数字顺序保持不变
- D:\hunting2014\小题目\字符串倒序
- NSArray数组的常用操作(遍历、排序、倒序、比较、与字符串的比较)
- 以单词为单位倒序输出一个字符串