本帖最后由 chouwayメ 于 2013-5-25 12:48 编辑
你的意思是?题目没看清楚.不是很懂.
下面是我自己大概练写了代码下,主要是通过编码查找所属编码的具体情况.
1:将所属不同 key:value 存入HashMap;
2:输入你想知道的编码
3:匹配HashMap中的key值,检验,并输出相应结果.- import java.io.*;
- import java.util.*;
- import java.util.Map.Entry;
- import java.util.regex.*;
- public class Test1
- {
- public static void main(String[] args) throws Exception{
- Map<Long,String> ms=new HashMap<Long,String>( );//建HashMap 装key:value
- ms.put(21401000000l,"省级编码");
- ms.put(21401030000l,"市级编码");
- ms.put(21401010400l,"市级编码");
- ms.put(21401010000l,"区县编码");
- ms.put(21401020000l,"区县编码");
- ms.put(21401010100l,"区县编码");
- ms.put(21401010200l,"区县编码");
- ms.put(21400000000l,"科所编码");
- ms.put(21401010300l,"科所编码");
- ms.put(21401040000l,"科所编码");
- ms.put(21402000000l,"科所编码");
- ms.put(21401010500l,"科所编码");
-
- BufferedReader bufIn=new BufferedReader(new InputStreamReader(System.in));//键盘输入
- String line=null;
- while((line=bufIn.readLine())!= null)
- {
-
- Long lon=Long.parseLong(line);
- for(Entry<Long, String> entry:ms.entrySet()) //通过高级for遍历
- {
- if(!line.matches("[0-9]{12}"))
- {
- System.out.println("非法编码!请输入12位编码...");
- break;
- }
- Long key=entry.getKey();
- Long check=Long.parseLong(line);
- if(check==key)
- {System.out.println(entry.getValue());break;}
- else
- {System.out.println("未编制号码");break;}
- };
- break;
-
- }
-
-
- }
- }
复制代码 |