[Csharp]
/*
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: number of occurrences and Reverse Order
* Author: Xue Guangchen
* Completion date: January 1, October 08, 2011
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: Write a class named MyClass and a method named CountChar in the class,
The return value is an integer and two parameters. The first parameter can be a string, an integer, a single precision, or a double precision,
The second parameter is a character, and the method function returns the number of times that the second parameter appears in the first parameter. For example, CountChar ("6221982", '2') returns 3.
Continue to write the method in this class, with the name Reconvert and one parameter,
But it can be a string, integer, single-precision, double-precision. The method function returns the reverse order of parameters. For example, Reconvert (6221982) returns 2891226
* Program output:
* End the comment in the program Header
*/
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Namespace MyClass
{
Class Program
{
Static void Main (string [] args)
{
Console. Write ("enter a string :");
String str = Console. ReadLine ();
Console. Write ("enter a character :");
Char ch = Console. ReadKey (). KeyChar;
Int number = CountChar (str, ch );
Console. WriteLine ("\ n character {0} appears in string {1} {2} Times \ n", ch, str, number );
String str1 = Reconvert (str );
Console. Write ("the reverse order of {0} is {1} \ n", str, str1 );
Console. ReadKey ();
}
Static int CountChar (string str, char ch)
{
Int num = 0;
For (int I = 0; I <str. Length; I ++)
{
If (str [I] = ch)
{
Num ++;
}
}
Return num;
}
Static string Reconvert (string str)
{
Char [] ch = new char [str. Length];
String str1 = "";
For (int I = str. Length-1, j = 0; I> = 0; I --, j ++)
{
Ch [j] = str [I];
Str1 + = ch [j]. ToString ();
}
Return str1;
}
}
}
Running result: