Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

counting repeated characters in a string in java

String s="mmababctamantlslwgikl";
    int distinct = 0 ;

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

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

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

        
    }
Comment

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;

    }

}
Comment

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);
   }

}
Comment

PREVIOUS NEXT
Code Example
Java :: root to leaf sum leetcode 
Java :: java dynamic method dispatch 
Java :: java print 
Java :: java length of matrix 
Java :: Hourglass Java 
Java :: check if sqlexception is duplicate entry java 
Java :: java find all of letter in string 
Java :: springdoc 
Java :: How to determine whether a graph contains a cycle, in Java? 
Java :: split number java 
Java :: spannable string in android java for color 
Java :: Java print class type 
Java :: spring boot save file to static folder 
Java :: sum of list java 
Java :: sort an int array java 
Java :: java arraylist deep copy 
Java :: Send image file to server useing Retrofit 
Java :: empty set java 
Java :: intellij 
Java :: iterate through an arraylist java 
Java :: android view set border programmatically 
Java :: addall java 
Java :: can interface have attributes java 
Java :: switch case in android studio - java 
Java :: arraylist input from user java 
Java :: jbutton border size java 
Java :: radio button in java 
Java :: throw error java 
Java :: how to draw a rectangle in libgdx 
Java :: reverseString 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =