Given a string, print the number of alphabets present in the string. Input: The first line of input contains an integer T denoting the number of test cases. The description of T test cases follows.Each test case contains a single string. Output: Print the number of alphabets present in the string.
This is a question i have been trying to solve this question on eclipse but it keeps throwing ArrayIndexoutOfBoundsException in line 7 of my code. I tried understanding what i've done wrong but i have not been able to. Could some one please explain whats wrong here . I have attached the code.
public class solution {
public static void main(String[] args){
String s = "baibiasbfi" ;
int count =0;
for(int i=0;i<=s.length();i++){
char[] a= s.toCharArray();
if(a[i]>='a'&& a[i]<='z'||a[i]>='A'&&a[i]<='Z')
count++;}
System.out.println(count);
}
}