java 判斷一個字串中的字元全是字母
阿新 • • 發佈:2019-02-12
記錄一個方法,用來判斷一個字串中字元是否全為字母 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; } }