KiKi想判断输入的字符是不是字母,请帮他编程实现。
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."); } } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String a = in.next(); if( a.toLowerCase().charAt(0) >='a' && a.toLowerCase().charAt(0)<='z') { System.out.println(a.charAt(0)+" is an alphabet."); } else { System.out.println(a.charAt(0)+" is not an alphabet."); } } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNextLine()){ char c=sc.nextLine().charAt(0); String type=Character.isLetter(c)?"":" not"; System.out.printf("%s is%s an alphabet.\n",c,type); } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ String toJudgeAlphabet = scanner.nextLine(); if(toJudgeAlphabet.matches("[a-zA-Z]")){ System.out.println(toJudgeAlphabet + " is an alphabet."); }else{ System.out.println(toJudgeAlphabet + " is not an alphabet."); } } } }
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.*; public class Main{ public static String getletter(String ch){ for(int i=0;i<ch.length();i++){ if(('a'<=ch.charAt(i)&&ch.charAt(i)<='z')|('A'<=ch.charAt(i)&&ch.charAt(i)<='Z')){ return ch+" is an alphabet."; } } return ch+" is not an alphabet."; } public static void main(String args[]){ Scanner input=new Scanner(System.in); while(input.hasNext()){ String ch=input.nextLine(); System.out.println(getletter(ch)); } } }
import java.util.Scanner; import java.util.regex.Pattern; /** * * @Title 判断是不是字母 * @Description KiKi想判断输入的字符是不是字母,请帮他编程实现。 * 输入描述: * 多组输入,每一行输入一个字符。 * 输出描述: * 针对每组输入,输出单独占一行,判断输入字符是否为字母,输出内容详见输出样例。 * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/16 11:21 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()) { String s = in.nextLine(); boolean v = Pattern.compile("[a-zA-Z]").matcher(s).matches(); if(v) { System.out.println(s + " is an alphabet."); } else { System.out.println(s+ " is not an alphabet."); } } } }
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."); } } } }
import java.util.*; public class Main { public static void main(String [] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { String s=sc.next(); if(s.matches("[a-zA-Z]")) { System.out.println(s+" is an alphabet."); } else { System.out.println(s+" is not an alphabet."); } } } }