Answers for "java program to return the duplicate characters from given string and also maximum occurrence of that duplicate character in a string in java"

1

counting repeated characters in a string in java

void Findrepeter(){
    String s="mmababctamantlslmag";
    int distinct = 0 ;

    for (int i = 0; i < s.length(); i++) {

        for (int j = 0; j < s.length(); j++) {

            if(s.charAt(i)==s.charAt(j))
            {
                distinct++;

            }
        }   
        System.out.println(s.charAt(i)+"--"+distinct);
        String d=String.valueOf(s.charAt(i)).trim();
        s=s.replaceAll(d,"");
        distinct = 0;

    }

}
Posted by: Guest on January-26-2020
1

counting repeated characters in a string in java

import java.io.*;
public class CountChar 
{

    public static void main(String[] args) throws IOException
    {
      String ch;
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
      System.out.print("Enter the Statement:");
      ch=br.readLine();
      int count=0,len=0;
        do
        {  
          try
          {
          char name[]=ch.toCharArray();
              len=name.length;
              count=0;
              for(int j=0;j<len;j++)
               {
                  if((name[0]==name[j])&&((name[0]>=65&&name[0]<=91)||(name[0]>=97&&name[0]<=123))) 
                      count++;
               }
              if(count!=0)
                System.out.println(name[0]+" "+count+" Times");
              ch=ch.replace(""+name[0],"");          
          }
          catch(Exception ex){}
        }
        while(len!=1);
   }

}
Posted by: Guest on January-26-2020
0

how to check that letter is not a number and is repeating or not in a sentence in java

private static boolean check(String input) {
    for (int i = 0; i < input.length(); i++) {
        char ch = input.charAt(i);
        if (Character.isLetter(ch) && input.indexOf(ch, i + 1) != -1) {
            return true;
        }
    }
    return false;
}
Posted by: Guest on August-10-2021
-1

java, how to find the most repeated character

private static String findMaxChar(String str) {
    char[] array = str.toCharArray();
    Set<Character> maxChars = new LinkedHashSet<Character>();

    int maxCount = 1;
    maxChars.add(array[0]);

    for(int i = 0, j = 0; i < str.length() - 1; i = j){
        int count = 1;
        while (++j < str.length() && array[i] == array[j]) {
            count++;
        }
        if (count > maxCount) {
            maxCount = count;
            maxChars.clear();
            maxChars.add(array[i]);
        } else if (count == maxCount) {
            maxChars.add(array[i]);
        }
    }

    return (maxChars + " = " + maxCount);
}
Posted by: Guest on January-02-2021

Code answers related to "java program to return the duplicate characters from given string and also maximum occurrence of that duplicate character in a string in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language