Java程序检查输入的字符是否为ASCII 7位数字和字符


检查输入的值是否为ASCII 7位数字和字符(字母数字),检查字符的ASCII值是否存在 −

A to Z
Or
a to z
Or
0 to 9

在此,我们有以下值 −

char one = '5';

现在,我们已经使用if-else对ASCII 7位数字和字符检查了一些条件。

if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
System.out.println("Given value is numeric and character (alphanumeric)!");
} else {
System.out.println("Given value is not numeric and character!");
}

示例

 实时演示

public class Demo {
public static void main(String []args) {
   char one = '5';
   if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
         System.out.println("Given value is numeric and character (alphanumeric)!");
      } else {
         System.out.println("Given value is not numeric and character!");
      }
   }
}

输出

Given value is numeric and character (alphanumeric)!

让我们看另一个示例 −

示例

 实时演示

public class Demo {
public static void main(String []args) {
   char one = 'V';
   if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
         System.out.println("Given value is numeric and character (alphanumeric)!");
      } else {
         System.out.println("Given value is not numeric and character!");
      }
   }
}

输出

Given value is numeric and character (alphanumeric)!

更新于: 2020年6月25日

108次观看

开启你的 职业生涯

通过完成课程获得认证

开始
广告