Home  >  Article  >  Java  >  Determine whether it is a letter in java

Determine whether it is a letter in java

尚
Original
2019-11-22 10:31:123620browse

Determine whether it is a letter in java

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] >= &#39;a&#39; && chars[i] <= &#39;z&#39;) || (chars[i] >= &#39;A&#39; && chars[i] <= &#39;Z&#39;);
            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] 914319badbce8bc36df946b5cf27aa76= '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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:what is java methodNext article:what is java method