My one test case is not working in this program

In case the length of the given string is 1, your code will output 1, which is wrong. To rectify this, change this initialization :

char ch=‘1’;

to

char ch = s.charAt(0);

Your approach is totally correct but as a suggestion, consider using a HashMap/frequency array for frequency-related questions to reduce the time complexity of your code to O(n).