java determines whether a string is a letter:
记录一个方法,用来判断一个字串中字符是否全为字母 public class MainClass { public static void main(String[] args){ String str = "hhhggdxszfff"; boolean is_boolean = isPhonticName(str); System.out.println(is_boolean); } public static boolean isPhonticName(String str) { char[] chars=str.toCharArray(); boolean isPhontic = false; for(int i = 0; i < chars.length; i++) { isPhontic = (chars[i] >= 'a' && chars[i] <= 'z') || (chars[i] >= 'A' && chars[i] <= 'Z'); if (!isPhontic) { return false; } } return true; } }
The above code traverses the string through a loop, and then uses chars[i] >= 'a' in the loop && chars[i] <= 'z') || (chars[i] >= 'A' && chars[i] <= 'Z' statement determines whether each character in the string is a letter.
For more java knowledge, please pay attention to java basic tutorial.
The above is the detailed content of Determine whether it is a letter in java. For more information, please follow other related articles on the PHP Chinese website!