黑马程序员技术交流社区

标题: 这是正则表达式的什么原因,费解 [打印本页]

作者: 747437484    时间: 2013-12-25 20:08
标题: 这是正则表达式的什么原因,费解
class  Test5  
{  
    public static void main(String[] args)  
    {  
        String regex="1[3458]\\d{4}(\\d)\\1{4}";  
        System.out.print("输入要检验的手机号码:");         
        Scanner sc=new Scanner(System.in); //接收键盘录入的电话号码,简单尝试IO流              
       //调用字符串的matches方法,并将boolean型结果赋给变量b         
       System.out.println("您输入的是"+sc.matches(regex)+"符合要求的电话号码");  //说matches那不对,但是我不懂
    }  
}  


作者: 776699    时间: 2013-12-25 20:49
  String regex="1[3458]\\d{9}";  
                System.out.print("输入要检验的手机号码:");         
                Scanner sc=new Scanner(System.in); //接收键盘录入的电话号码,简单尝试IO流              
               //调用字符串的matches方法,并将boolean型结果赋给变量b         
               System.out.println("您输入的是"+sc.next(regex)+"符合要求的电话号码");  
可以这么写, Scanner没有matches(String str)方法
作者: 776699    时间: 2013-12-25 20:50
String 有matches(string str)方法,Scanner,没有
作者: 卖火柴    时间: 2013-12-25 20:55
Scanner和string 不一样的,Scanner没有matches(string str)方法




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2