Java 程序检查字符是否为 ASCII 7 位可打印字符
若要检查输入的值是否为 ASCII 7 位可打印字符,请检查字符的 ASCII 值是否大于或等于 32 且小于 127。这些是控制字符。
在此处,我们有一个字符。
char one = '^';
现在,我们通过 if-else 检查可打印字符的条件。
if (c >= 32 && c < 127) {
System.out.println("Given value is printable!");
} else {
System.out.println("Given value is not printable!");
}示例
public class Demo {
public static void main(String []args) {
char c = '^';
System.out.println("Given value = "+c);
if (c >= 32 && c < 127) {
System.out.println("Given value is printable!");
} else {
System.out.println("Given value is not printable!");
}
}
}输出
Given value = ^ Given value is printable!
让我们看另一个示例,其中给定的值是一个字符。
示例
public class Demo {
public static void main(String []args) {
char c = 'y';
System.out.println("Given value = "+c);
if ( c >= 32 && c < 127) {
System.out.println("Given value is printable!");
} else {
System.out.println("Given value is not printable!");
}
}
}输出
Given value = y Given value is printable!
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言
C++
C#
MongoDB
MySQL
Javascript
PHP