Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find the letter that occurs most in a string java

// Java program to output the maximum occurring character
// in a string
 
public class GFG
{
    static final int ASCII_SIZE = 256;
    static char getMaxOccuringChar(String str)
    {
        // Create array to keep the count of individual
        // characters and initialize the array as 0
        int count[] = new int[ASCII_SIZE];
      
        // Construct character count array from the input
        // string.
        int len = str.length();
        for (int i=0; i<len; i++)
            count[str.charAt(i)]++;
      
        int max = -1;  // Initialize max count
        char result = ' ';   // Initialize result
      
        // Traversing through the string and maintaining
        // the count of each character
        for (int i = 0; i < len; i++) {
            if (max < count[str.charAt(i)]) {
                max = count[str.charAt(i)];
                result = str.charAt(i);
            }
        }
      
        return result;
    }
     
    // Driver Method
    public static void main(String[] args)
    {
        String str = "sample string";
        System.out.println("Max occurring character is " +
                            getMaxOccuringChar(str));
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java -jar -l resourceses.porperties -i ejemplo.txt -o inject.bin 
Java :: Java Advantages of Anonymous Classes 
Java :: dialog background dimming in android 
Java :: gradle use local path 
Java :: jfxsa-run-no-another-jvm java fxml error 
Java :: how to set to nothing a ComboBox in java 
Java :: what is xml file in java 
Java :: copy array of objects in java 
Java :: para que sirve getcontentpane en java 
Java :: aabb collision java 
Java :: merced A class 
Java :: how to decode a ByteArray to Bitman in adroid 
Java :: UIManager.setLookAndFeel Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke because "style" is null 
Java :: how to use old android studio project 
Java :: jdned 
Java :: public CustomAdapter(Context context, ArrayList<HashMap data, int resource, String[] from, int[] to) 
Java :: zebra zpl print java 
Java :: int p=10, q; switch(p) { case1: q=p*2; break; case2: q=p+2; break; case3: q=p-2; break; } 
Java :: comvertir a java 
Java :: mostrar divisores java 
Java :: what are construtcor java 
Java :: leftView 
Java :: how to return custom value in api spring boot 
Java :: java method 
Java :: mock dynamodb unit 
Java :: gggghfh 
Java :: .class to .java 
Java :: What is the name of the Android function that is used to update the UI (user interface) from a background thread? 
Java :: java producer consumer queue 
Java :: Java instanceof in Interface 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =