从键盘输入一个手机号,首先判断手机号是否合法。如果合法,进一步判断手机号的运营商(中国电信、中国联通、中国移动)。
public boolean matches(String regex)
String s="18923456781";
System.out.println(s.matches("1\\d{10}"));
第一步:从键盘输入一个手机号。
s=in.nextLine();
第二步:判断手机号的合法性。
第三步:如果手机号是合法的,继续判断手机号的运营商
if(s. matches("1\\d{10}"))
{
//手机号是合法的,继续判断
if(s. startsWith(“189”))
{
//输出
}
else if(s. startsWith(“139”))
{
//输出
}
……
}
else
{
//输出手机号是非法的。
}
public boolean endsWith(String suffix)