Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Max occured character in a string
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Console.WriteLine(MostOccurringCharInString("aaaacffffdgg")); } public static char MostOccurringCharInString(string charString) { int mostOccurrence = -1; char mostOccurringChar = ' '; foreach (char currentChar in charString) { int foundCharOccreence = 0; foreach (char charToBeMatch in charString) { if (currentChar == charToBeMatch) foundCharOccreence++; } if (mostOccurrence < foundCharOccreence) { mostOccurrence = foundCharOccreence; mostOccurringChar = currentChar; } } return mostOccurringChar; } } }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
loop exmple
FizzBuzz Solution
Ternary Operator
type comparison
yari
a
pointer
test
prime number
any predicate test
stackse - search stackoverflow differently
Please log in to post a comment.