Java程序检查字符是否为ASCII 7位数字
要检查输入的值是否为ASCII7位数字,请检查从'0'到'9'的字符。
在这里,我们有一个数字字符。
char one = '9';
现在,我们检查了if-else条件是否是数字字符,从'0'到'9'
if (c >= '0' && c <= '9') {
System.out.println("给定值是数字!");
} else {
System.out.println("给定值不是数字!");
}示例
public class Demo {
public static void main(String []args) {
char c = '9';
System.out.println("Given value = "+c);
if (c >= '0' && c <= '9') {
System.out.println("给定值是数字!");
} else {
System.out.println("给定值不是数字!");
}
}
}输出结果
Given value = 9 给定值是数字!
让我们看看另一个示例,其中我们检查数字字符。但是,此处要检查的给定值不是数字。
示例
Public class Demo {
public static void main(String []args) {
char c = 's';
System.out.println("Given value = "+c);
if (c >= '0' && c <= '9') {
System.out.println("给定值是数字!");
} else {
System.out.println("给定值不是数字!");
}
}
}输出结果
Given value = s 给定值不是数字!
现在让我们再看一个示例,其中我们检查数字字符。但是,此处要检查的给定值不是数字。
示例
public class Demo {
public static void main(String []args) {
char c = '-';
System.out.println("Given value = "+c);
if (c >= '0' && c <= '9') {
System.out.println("给定值是数字!");
} else {
System.out.println("给定值不是数字!");
}
}
}输出结果
Given value = - 给定值不是数字!
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短