Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Test

using System; 

namespace charCountDemo {  
   public class Example { 
      public static void Main(){ 
         String str = "abracadabra"; 
         int []charCount = new int[256]; 
         int length = str.Length; 
         for (int i = 0; i < length; i++){
            charCount[str[i]]++; 
         }
         int maxCount = -1; 
         char character = ' ';
         for (int i = 0; i < length; i++){ 
            if (maxCount < charCount[str[i]]){ 
               maxCount = charCount[str[i]]; 
               character = str[i]; 
            } 
         }  
         Console.WriteLine("The string is: " + str);
         Console.WriteLine("The highest occurring character in the above string is: " + character);
         Console.WriteLine("Number of times this character occurs: " + maxCount); 
      } 
   } 
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.