package com.altafjava.coos.test;
public class CountOccurrences2 {
public static void main(String[] args) {
String s="annotation";
System.out.println("Original String = "+s);
while(s.length()!=0){
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(0)==s.charAt(i))
count++;
}
System.out.println(s.charAt(0)+" = "+count);
s=s.replaceAll(s.charAt(0)+"", "");
}
}
}
public class CountOccurrences2 {
public static void main(String[] args) {
String s="annotation";
System.out.println("Original String = "+s);
while(s.length()!=0){
int count=0;
for(int i=0;i<s.length();i++){
if(s.charAt(0)==s.charAt(i))
count++;
}
System.out.println(s.charAt(0)+" = "+count);
s=s.replaceAll(s.charAt(0)+"", "");
}
}
}
0 Comment to "How to count occurrences of each character of a string without using Regular Expression in java?"
Post a Comment