Java - Write code to check if a char is Alphabet Or Numeric

Requirements

Write code to check if a char is Alphabet Or Numeric

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(isAlphabetOrNumeric(str));
    }//from  w  ww  . ja  v a  2s .c  o m

    public static boolean isAlphabetOrNumeric(String str) {
        for (int index = 0; index < str.length(); index++) {
            char chr = str.charAt(index);
            if (!isAlphabet(chr) && !Character.isDigit(chr)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isAlphabet(char chr) {
        return isLowerEnglishCharacter(chr) || isUpperEnglishCharacter(chr);
    }

    public static boolean isAlphabet(String str) {
        for (int index = 0; index < str.length(); index++) {
            char chr = str.charAt(index);
            if (!isAlphabet(chr)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isLowerEnglishCharacter(char chr) {
        int lowerStart = 97;//'a'
        int lowerEnd = 122;//'z'
        int code = (int) chr;
        return code >= lowerStart && code <= lowerEnd;
    }

    public static boolean isUpperEnglishCharacter(char chr) {
        int upperStart = 65;//'A'
        int upperEnd = 90;//'Z'
        int code = (int) chr;
        return code >= upperStart && code <= upperEnd;
    }
}