Title Description
Write an instance method getCountChar method. This method has two parameters, the first parameter may be a string s, the second parameter C character, the method returns the value of the second parameter in the number of occurrences of the first parameter. For example, CountChar ( "6221982", ' 2') returns a value of 3.
Some program code has been given.
the System the using;
the using the System.Collections.Generic;
the using the System.Linq;
the using the System.Text;
the using System.Threading.Tasks;
namespace the ConsoleApplication1
{
class Program
{
static void the Main (String [] args)
{
String Console.ReadLine STR = ( );
char CH = (char) Console.Read ();
Program Pro = new new Program ();
Console.WriteLine (pro.getCountChar (STR, CH));
//Console.ReadKey ();
}
Public int getCountChar (S String, char C) {
//
Fill code here
//
}
}
}
When submitting, please submit the entire topic! ! !
Some program code has been given.
the System the using;
the using the System.Collections.Generic;
the using the System.Linq;
the using the System.Text;
the using System.Threading.Tasks;
namespace the ConsoleApplication1
{
class Program
{
static void the Main (String [] args)
{
String Console.ReadLine STR = ( );
char CH = (char) Console.Read ();
Program Pro = new new Program ();
Console.WriteLine (pro.getCountChar (STR, CH));
//Console.ReadKey ();
}
Public int getCountChar (S String, char C) {
//
Fill code here
//
}
}
}
Entry
A string s, a character c
Export
The number of occurrences of character c in the string s
Sample input
6221982
2
Sample Output
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; Count the number of namespace strings of numeric characters { class Program { static void Main(string[] args) { string str = Console.ReadLine(); char ch = (char)Console.Read(); Program pro = new Program(); Console.WriteLine(pro.getCountChar(str, ch)); //Console.ReadKey(); } public int getCountChar(String s, char c){ // int num = 0; for (int i = 0; i < s.Length; ++i) { if (s[i] == c) { a ++; } } return num; // } } }