将字符串倒序

来源:互联网 发布:蜘蛛池域名收录 编辑:程序博客网 时间:2024/05/11 21:39
.继续在该类中编写一下方法,名称为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();        }    }}

0 0
原创粉丝点击