您的位置:首页 > 其它

将字符串倒序

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();

        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: