今天做的手机号码鉴别小程序,针对移动和连通的。
呵呵,今天上午做的,编译通过,主要功能是验证号码是移动的还是连通的号。做是做出来了,感觉有点乱,希望大家看看哪还要修改~~明天要交了。。
package File;
/*一段手机号码验证的程序
*/
class Error extends Exception
{
String s;
Error(String s)
{
this.s=s;
}
void tostring()
{
System.out.println(s);
}
}
class yinqing {
void jisuan(String s) throws Error{
String[] number={"135","136","137","138","139","159","134"};
String[] liantong={"133","132","130","131"};
char[] buf=new char[3];
char[] Lbuf=new char[3];
s.getChars(0, 3, Lbuf, 0);
s.getChars(0, 3, buf, 0);
String str=new String(buf);
String Lstr=new String(Lbuf);
if((s.length()==11))
{
for(int i=0;i<7;i++)
{
while(number[i].equals(str))
{
System.out.println("我是移动");
break;
}
}
for(int j=0;j<4;j++)
while(liantong[j].equals(Lstr))
{
System.out.println("我是联通");
break;
}
}
else
throw new Error("这是手机号嘛?我做个程序容易嘛我。");
}
}
public class NetWork_2 {
public static void main(String[] args) {
yinqing y=new yinqing();
try
{
y.jisuan("13861588939");
}
catch(Error e)
{
e.tostring();
}
}
}
[解决办法]
这些东西最好用正则表达式一句话可以解决
[解决办法]
这是手机号嘛?我做个程序容易嘛我。
。。。。。
[解决办法]
- Java code
package File; /*一段手机号码验证的程序 */ class Error extends Exception { String s; Error(String s) { this.s=s; } void tostring() { System.out.println(s); } } class yinqing { void jisuan(String s) throws Error{ String[] number={"135","136","137","138","139","159","134"}; String[] liantong={"133","132","130","131"}; char[] buf=new char[3]; char[] Lbuf=new char[3]; s.getChars(0, 3, Lbuf, 0); s.getChars(0, 3, buf, 0); String str=new String(buf); String Lstr=new String(Lbuf); if((s.length()==11)) { for(int i=0;i <7;i++) { while(number[i].equals(str)) { System.out.println("我是移动"); break; } } for(int j=0;j <4;j++) while(liantong[j].equals(Lstr)) { System.out.println("我是联通"); break; } } else throw new Error("这是手机号嘛?我做个程序容易嘛我。"); } } public class NetWork_2 { public static void main(String[] args) { yinqing y=new yinqing(); try { y.jisuan("13861588939"); } catch(Error e) { e.tostring(); } } }