KiKi想判断输入的字符是不是字母,请帮他编程实现。
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ char c1 = sc.next().charAt(0); if(c1 >= 'A' && c1 <= 'Z' || c1 >= 'a' && c1 <= 'z'){ System.out.println(c1+" is an alphabet."); }else{ System.out.println(c1+" is not an alphabet."); } } } }
#include<stdio.h> int main() { char a = '0'; while (scanf("%c", &a) != EOF) { if (a == '\n') continue; //65-90是小写字母,97-122是大写字母 if ((a >= 65 && a <= 90) || (a >= 97 && a <= 122)) printf("%c is an alphabet.\n", a); else printf("%c is not an alphabet.\n", a); } return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { char a = sc.next().charAt(0); boolean n = Character.isLetter(a); System.out.print(a); String m = n ? " is an alphabet." : " is not an alphabet."; System.out.println(m); } }}
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()){ String str=sc.next(); if(str.matches("[A-Za-z]")){ System.out.println(str+" is an alphabet."); }else { System.out.println(str+" is not an alphabet."); } } } }
#include <stdio.h> int main() { char ch; while(scanf("%c",&ch)!=EOF) { getchar(); if('a'<=ch&&ch<='z'||'A'<=ch&&ch<='Z') { printf("%c is an alphabet.\n",ch); } else{ printf("%c is not an alphabet.\n",ch); } } return 0; }
public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()){ String al = in.nextLine(); //将字符串转为字符,并将字母转换为小写 char al_lower = Character.toLowerCase(al.charAt(0)); //判断 if (al_lower >= 'a' && al_lower <= 'z'){ System.out.println(al + " is an alphabet."); } else { System.out.println(al + " is not an alphabet."); } } }