Home > Java > JavaBase > body text

Determine whether it is a letter in java

Release: 2019-11-22 10:31:12
Original
3663 people have browsed it

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;
    }
 
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template