从用户读取一个字符,以验证它是否位于a和z之间(小写和大写)。如果是,则为字母。
import java.util.Scanner; public class AlphabetOrNot { public static void main(String args[]){ System.out.println("Enter a character :: "); Scanner sc = new Scanner(System.in); char ch = sc.next().charAt(0); if(((ch >= 'A' && ch <= 'Z')||ch >= 'a' && ch <= 'z') ){ System.out.println("Given character is an alphabet"); }else{ System.out.println("Given character is not an alphabet"); } } }
输出结果
Enter a character :: d Given character is an alphabet