public class MyClass {
public static char GetSecondMostFrequentChar(String s) {
int[] count = new int[256]; // 256 = ASCII table size
for (int i = 0; i < s.length(); i++) {
count[s.charAt(i)]++;
}
int first = 0;
int second = 0;
for (int i = 0; i < 256; i++) {
if (count[i] > count[first]) {
second = first;
first = i;
}
else if (count[i] > count[second] && count[i] != count[first]) {
second = i;
}
}
return (char)second;
}
public static void main(String args[]) {
String str = "bbaddddccce";
System.out.print(GetSecondMostFrequentChar(str));
}
}
/*
run:
c
*/