I want to write a static method to which the string is passed, and which checks if the string consists of just letters and spaces. I can use the String length () and charAt (i) methods as needed.
I thought something like the following: (Sorry for the pseudocode)
public static boolean onlyLettersSpaces(String s){
for(i=0;i<s.length();i++){
if (s.charAt(i) != a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) {
return false;
break;
}else {
return true;
}
}
I know that there is probably a mistake in my coding, and there is probably a much simpler way to do this, but please let me know your suggestions!
source
share