counting repeated characters in a string in java
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);
}
}Map<Character,Integer> map = new HashMap<Character,Integer>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (map.containsKey(c)) {
int cnt = map.get(c);
map.put(c, ++cnt);
} else {
map.put(c, 1);
}
} 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;
}
}
Also in Java:
- Title
- java create new object
- Category
- Java
- Title
- how to make an arraylist java
- Category
- Java
- Title
- excel data formatter in java
- Category
- Java
- Title
- web app runtime for java
- Category
- Java
- Title
- editer un label java
- Category
- Java
- Title
- array in java stack overflow
- Category
- Java
- Title
- dataframe to dict without index
- Category
- Java
- Title
- how to create dynamic string array in java
- Category
- Java
- Title
- how to find powers in java
- Category
- Java
- Title
- java pass array as method parameter
- Category
- Java
- Title
- Java array equals
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- java switch display panel
- Category
- Java
- Title
- java.lang.ClassCastException: cannot be cast to javax.servlet.Servlet
- Category
- Java
- Title
- system.out.println shortcut
- Category
- Java
- Title
- java compareto
- Category
- Java
- Title
- copy file with byte java
- Category
- Java
- Title
- android elevation not working
- Category
- Java
- Title
- jbutton close jframe java
- Category
- Java
- Title
- lightweight java game library
- Category
- Java
- Title
- ujava saum of positive integers
- Category
- Java
- Title
- convert integer array to string array
- Category
- Java
- Title
- java get current date without time
- Category
- Java
- Title
- spigot disable join message
- Category
- Java
- Title
- foreach java
- Category
- Java
- Title
- FileNotFoundException: properties/fortunes.txt (No such file or directory)
- Category
- Java
- Title
- arraylist array
- Category
- Java
- Title
- java int to binary
- Category
- Java
- Title
- how to interrupt a void java
- Category
- Java
- Title
- Java Read Files
- Category
- Java
- Title
- java enum
- Category
- Java
- Title
- how to cut a certion part from a string in java
- Category
- Java
- Title
- get drawable with string android java
- Category
- Java
- Title
- map.keyset in java
- Category
- Java
- Title
- what is a variable in java
- Category
- Java
- Title
- java iterate over a string
- Category
- Java
- Title
- socket in java
- Category
- Java
- Title
- how to make a variable unchangeable in java
- Category
- Java
- Title
- java treemap
- Category
- Java
- Title
- get number of items in arraylist java
- Category
- Java
- Title
- méthode retourne nom classe java
- Category
- Java
- Title
- what is graphics default color java
- Category
- Java
- Title
- length of string java
- Category
- Java
- Title
- how timer class and display to jtextfield w3schools in java
- Category
- Java
- Title
- java newinstance alternative
- Category
- Java
- Title
- hide elements android
- Category
- Java
- Title
- for loop in java stack overflow
- Category
- Java
- Title
- java double 2 decimal
- Category
- Java
- Title
- java define a generic class that produces
- Category
- Java
- Title
- pascal's triangle java 2d array
- Category
- Java
- Title
- string a int java
- Category
- Java
- Title
- listview get selected java
- Category
- Java
- Title
- how to fill a 2d array in java
- Category
- Java
- Title
- how to import an arraylist in java
- Category
- Java
- Title
- ARE THERE POINTER IN JAVA
- Category
- Java
- Title
- java lerp
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- most common element in list java
- Category
- Java
- Title
- how to end a program in an if statement java
- Category
- Java
- Title
- loop array using stream java
- Category
- Java
- Title
- java create jframe
- Category
- Java
- Title
- java read integer from text file into array scanner
- Category
- Java
- Title
- java convert edittext to double
- Category
- Java
- Title
- binary search java
- Category
- Java
- Title
- java find if element of list in present in another list
- Category
- Java
- Title
- java string to character stream
- Category
- Java
- Title
- iterate through hashmap in java
- Category
- Java
- Title
- print out value java
- Category
- Java
- Title
- two dimensional array in java example program
- Category
- Java
- Title
- java 8 hashmap example stackoverflow
- Category
- Java
- Title
- reading in lines from a file java
- Category
- Java
- Title
- java swing dialog box
- Category
- Java
- Title
- close scanner java
- Category
- Java
- Title
- how to add element to arraylist
- Category
- Java
- Title
- loop through java object
- Category
- Java
- Title
- Enums injava
- Category
- Java
- Title
- java djikstra's algorithm
- Category
- Java
- Title
- how to format a datetime object to show date and time and milliseconds in java
- Category
- Java
- Title
- how to declare list of object in java as constant
- Category
- Java
- Title
- print a list java
- Category
- Java
- Title
- java rest client response json
- Category
- Java
- Title
- math min max java
- Category
- Java
- Title
- how do i print text in java
- Category
- Java
- Title
- print a string java
- Category
- Java
- Title
- esponente in java
- Category
- Java
- Title
- index 1 out of bound for length 1 java
- Category
- Java
- Title
- parseints(str) java
- Category
- Java
- Title
- how to open a webpage with java
- Category
- Java
- Title
- binary search tree insert java
- Category
- Java
- Title
- demo java file
- Category
- Java
- Title
- déclarer un tableau en java
- Category
- Java
- Title
- creating the functional interface in java
- Category
- Java
- Title
- array string java in one line
- Category
- Java
- Title
- java string to int
- Category
- Java
- Title
- array of objects in java
- Category
- Java
- Title
- change fragment in android studio
- Category
- Java
- Title
- java for
- Category
- Java
- Title
- java sleep in code
- Category
- Java
- Title
- exception handling and reprompting
- Category
- Java
- Title
- java 8 string to localdate
- Category
- Java