Array-promo

Question

program to print maximum occurring characters in a given sentence. 

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					

import java.util.Scanner;
public class maximumOccurringCharacterInSentence 
{  
    public static void main(String[] args)
    {  
        String sen="";
        char ch=' ',ch1=' ',maxOccuring=' ';
        int i=0,len=0,count=0,max=0;
        Scanner sc = new Scanner(System.in);    
        
        System.out.println("Enter a sentence");   
        sen = sc.nextLine(); 
        sen=sen.toLowerCase();
        
        len=sen.length();
        for(ch='a';ch<='z';ch++)
        {
            count=0;
            for(i=0;i< len;i++)
            {
                ch1=sen.charAt(i);
            
                if(ch1==ch)
                {
                    count++;
                }
                
            }
            if(count> max)
            {
                max=count;
                maxOccuring=ch;
                
            }
        }
        System.out.println("maximum occurring character in given sentence:"+maxOccuring);
    }  
}    


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *