If I understood your question well: Here you have one of many solutions:
public class FreqString {
public static void main(String[] args){
String s = ';Guadalajara';;
char[] c = s.toCharArray(); // converting to a char array
int freq =0;
for(int i = 0; i%26lt; c.length;i++) {
if(c[i]=='a') // looking for 'a' only
freq++;
}
System.out.println(';Total chars ';+c.length);
System.out.println(';Number of 'a' are ';+freq);
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment