B1 【测试自动化6】城市电话号码
java代码:
import java.util.Scanner;
public class PhoneNumber {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);
char[] c1,c2,c3;
boolean flag0 = false,flag1=false,flag2 = false,flag3 = false;
while(cin.hasNext()){
String a = cin.nextLine();
String b = cin.nextLine();
String c = cin.nextLine();
c1 = a.toCharArray();
c2 = b.toCharArray();
c3 = c.toCharArray();
if(!(c1.length==0)){
if((c1.length!=3)){
flag0 =true;
break;
}
}
if(c2.length!=3&&c3.length!=4){
flag0 =true;
}
for(int i =0;i<c1.length;i++){
if(!(c1[i]>='0'&&c1[i]<='9')){
flag1=true;
break;
}
}
for(int i = 0;i<c2.length;i++){
if(i ==0){
flag2=c2[0]!='0'?false:true;
break;
}
else if (!(c2[i]>='0'&&c2[i]<='9')){
flag2= true;
break;
}
}
for(int i =0;i<c3.length;i++){
if(!(c3[i]>='0'&&c3[i]<='9')){
flag3 = true;
break;
}
}
if(flag0||flag1||flag2||flag3){
System.out.println(1);
}
else{
System.out.println(0);
}
}
}
}
JDK1.7编译通过。