日期:2014-05-18  浏览次数:20710 次

java.util.Matcher.matchers返回的值是什么
直接上代码
public static void main(String[] args) {
// 从键盘输入
Scanner sc = new Scanner(System.in);
System.out.println("请输入密钥(纯数字):");
String key = sc.next();
System.out.println("请输入要加密的字符串:");
sc.nextLine(); // 跳过"\n"
String text = sc.nextLine();
// 用正则判断一下密钥是否纯数字
Matcher matcher = Pattern.compile("\\d").matcher(key);
System.out.println(matcher.matches());
if(matcher.matches()){
System.out.println("输入的密钥不是纯数字!");
}else{
Ciphertext.getCiphertext(key.trim(), text.trim());
}

}

运行结果:
请输入密钥(纯数字):
123
请输入要加密的字符串:
123
false
246



我不明白的是,为什么会出现false.我输入的是123,纯数字了,也符合"\\d"的规则了吧,为什么还是false呢?

------解决方案--------------------
\\d+ \\d*




------解决方案--------------------
该回复于2013-12-28 17:18:06被管理员删除