Write code to check if a char is Alphabet Or Numeric
//package com.book2s; public class Main { public static void main(String[] argv) { String str = "book2s.com"; System.out.println(isAlphabetOrNumeric(str)); }/*from w ww . j av a2s.c om*/ 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; } }